Basic SQL database queries

SQL CREATE DATABASE

The CREATE DATABASE statement is used to create a database.

 

The Syntax of SQL CREATE DATABASE is

CREATE DATABASE Database_name;

 

Example

CREATE DATABASEmy_db;

 

In MYSQL a Database must be created first to insert data into it

In ORACLE you do not need to create a Database you can directly create tables to insert data.

 

NOTE 1: Every Database name must be Unique in RDBMS.

NOTE 2: Here the commands we use are based on MYSQL Database.

 

SQL DROP DATABASE

SQL DROP statement is used to completely remove the data from the table name in a database.

To remove a Database you need to use SQL DROP DATABASE statement.

The syntax for SQL DROP DATABASE is

DROP DATABASEDatabase_name;

 

If you use this command the tables, indexes inside the database will also be removed. So the command should be used only when it is required.

Example:

DROP DATABASEmy_db;

 

SQL RENAME DATABASE

SQL RENAME is used to change the name of the table or database. It is used

The syntax for SQL RENAME DATABASE is

RENAME DATABASEold_database_nameTOnew_database_name;

 

To perform rename command in SQL SERVER You can use ALTER command and it can be used as follows

 

ALTER DATABASEold_nameMODIFY NAME = new_name.

 

Example:

RENAME DATABASEmy_dbTOmy_database;

                                                                 Or

ALTER DATABASEmy_dbMODIFY NAME = my_database.

 

SQL SELECT DATABASE

SQL SELECT command is used to select a Database. In MYSQL you need to select a database first in order to perform operations on it.

The Syntax for the SQL SELECT DATABASE is

SELECT DATABASEDatabase_name;

                                                                   Or

USE DATABASEDatabase_name;

 

Example:

SELECT DATABASEmy_db;

                                                                  Or

USE DATABASEmy_db;