
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 6705 Articles for Database

961 Views
The syntax to add a new column to an existing table is quite straightforward.ALTER TABLE table_name ADD COLUMN column_name column_type column_constraint;Say you have existing table marks. An example is given below −serial_nonameroll_nomarks_obtainedperc_marksmax_marksdate_of_entry1Yash2642421002021-01-302Isha5617587.52002021-01-30Now, suppose you want to add a column named subject. You can do that using −ALTER TABLE marks ADD COLUMN subject VARCHAR;Now if you query the table again using, SELECT * from marksYou will see the following output −serial_nonameroll_nomarks_obtainedperc_ marksmax_ marksdate_ of_ entrysubject1Yash2642421002021-01-30[null]2Isha5617587.52002021-01-30[null]Note that the values in the subject column are null because we have just created the column, not populated it. We can populate it using the UPDATE ... Read More

322 Views
Creating a table in PostgreSQL is pretty straightforward. The syntax is −CREATE TABLE table_name( Column1_name type optional_constraint, Column2_name type optional_constraint, . . . ColumnN_name type optional constraint );If you want to make sure that your table is created only if it doesn’t already exist, you can specify that explicitly −CREATE TABLE IF NOT EXISTS table_name(…);An example of table creation is given below −CREATE TABLE marks( serial_no SERIAL PRIMARY KEY, name VARCHAR, roll_no INTEGER, marks_obtained INTEGER, perc_marks DOUBLE PRECISION, max_marks INTEGER, date_of_entry DATE );The above command will just ... Read More

5K+ Views
Sometimes, some rogue queries can take too long to execute. If the queries are blocking in nature, i.e., they restrict access to a table while they are executing, then any other query on the same table will be put on hold, and this leads to a pile-up of queries. This can, depending on your DB load, even cause the max connections to be exceeded. Luckily, you can easily kill long queries in pgAdmin.Go to Dashboard in your pgAdmin. At the bottom, in the Server Activity section, under the Sessions Tab, you can see all the Active queries.Now, notice the cross ... Read More

4K+ Views
Querying a DB in pgAdmin is quite straightforward. Locate your DB in the Servers dropdown on the left, and extend its dropdown, till you see the Schemas dropdown.Once you click on Schemas, the black button on the top, with the DB symbol and the play arrow will become clickable.Click on that button, and you will see a Query Tab open up. That’s it, you can type your queries for this particular DB in that box, and click the play arrow button to execute the queries.The output will be seen on the bottom, in the ‘Data Output’ section.Read More

657 Views
To check for such conditions, use IF() in MySQL.Let us create a table −Examplemysql> create table demo89 -> ( -> duedate date -> ); Query OK, 0 rows affected (0.78Insert some records into the table with the help of insert command −Examplemysql> insert into demo89 values('2020-01-10'); Query OK, 1 row affected (0.55 mysql> insert into demo89 values(null); Query OK, 1 row affected (0.13 mysql> insert into demo89 values('2020-11-29'); Query OK, 1 row affected (0.15 mysql> insert into demo89 values('2019-11-29'); Query OK, 1 row affected (0.09Display records from the table using select statement −Examplemysql> select ... Read More

2K+ Views
To create a table, you need to insert below line into application.properties −spring.jpa.hibernate.ddl-auto=updateHere, Hibernate will create the table demo88 automatically. The application.properties code is as follows −spring.datasource.platform=mysql spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect spring.jpa.hibernate.ddl-auto=update server.port=8191 spring.datasource.driverClassName=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/sampledatabase spring.datasource.username=root spring.datasource.password=123456The demo88 entity class is as follows to create table columns −Examplepackage com.automaticallytablecreation; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table public class demo88 { @Id private int id; @Column(name="name") private String name; }The main class code is as follows −Examplepackage com.automaticallytablecreation; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class AutomaticTableApplication { public static void main(String[] ... Read More

4K+ Views
For this, you can use the ResultSet concept. For connection, we will be using the MySQL JDBC Driver.Let us create a table −Examplemysql> create table demo87 -> ( -> name varchar(20), -> age int -> ) -> ; Query OK, 0 rows affected (0.62Insert some records into the table with the help of insert command −Examplemysql> insert into demo87 values('John', 21); Query OK, 1 row affected (0.15 mysql> insert into demo87 values('David', 23); Query OK, 1 row affected (0.12 mysql> insert into demo87 values('Bob', 22); Query OK, 1 row affected (0.16Display records from ... Read More

604 Views
For this, you can use ISNULL in MySQL.Let us create a table −Examplemysql> create table demo86 -> ( -> value1 varchar(20) -> , -> value2 varchar(20) -> ); Query OK, 0 rows affected (2.77Insert some records into the table with the help of insert command −Examplemysql> insert into demo86 values(null, null); Query OK, 1 row affected (0.34 mysql> insert into demo86 values(null, 'John'); Query OK, 1 row affected (0.16 mysql> insert into demo86 values('David', 'Mike'); Query OK, 1 row affected (0.17 mysql> insert into demo86 values('Sam', null); Query OK, 1 row affected ... Read More

8K+ Views
To sum rows with same ID, use the GROUP BY HAVING clause.Let us create a table −Examplemysql> create table demo84 -> ( -> id int, -> price int -> ) -> ; Query OK, 0 rows affected (0.60Insert some records into the table with the help of insert command −Examplemysql> insert into demo84 values(1, 2000); Query OK, 1 row affected (0.08 mysql> insert into demo84 values(1, 2000); Query OK, 1 row affected (0.14 mysql> insert into demo84 values(2, 1800); Query OK, 1 row affected (0.14 mysql> insert into demo84 values(2, 2200); Query ... Read More

920 Views
For this, use INSERT INTO SELECT statement.Let us create a table −Examplemysql> create table demo82 -> ( -> id int, -> name varchar(20) -> ); Query OK, 0 rows affected (2.06Insert some records into the table with the help of insert command −Examplemysql> insert into demo82 values(100, 'John'); Query OK, 1 row affected (0.14 mysql> insert into demo82 values(101, 'Bob'); Query OK, 1 row affected (0.32 mysql> insert into demo82 values(101, 'David'); Query OK, 1 row affected (0.09 mysql> insert into demo82 values(101, 'Mike'); Query OK, 1 row affected (0.12 mysql> insert ... Read More