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 DATABASE my_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: 

Every Database name must be Unique in RDBMS.

 

Note: 

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 DATABASE Database_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 DATABASE my_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 DATABASE old_database_nameTOnew_database_name;

 

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

 

ALTER DATABASE old_nameMODIFY NAME = new_name.

 

Example:

RENAME DATABASE my_dbTOmy_database;

                                                                 Or

ALTER DATABASE my_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 DATABASE Database_name;

                                                                   Or

USE DATABASE Database_name;

 

Example:

SELECT DATABASE my_db;

                                                                  Or

USE DATABASE my_db;