SQL CREATE DATABASE
SQL commands are available for creating a new database and changing or modifying structure of the tables in the database. The set of SQL commands are collectively called Data Definition Language (DDL).
Features of the DDL.
- DDL allow us to define and create new database and tables.
- DDL allows us to remove the tables from the database and we can easily change the table's structure.
- By using DDL, we can control the physical storage of the data in database.
- It allows us to define the virtual tables of data (ex :views)
- We can easily make the security related control over on the databases.
- We can build an index for on table so that we can access those table faster.
In DDL, there are three main SQL verbs which act as the basic core of the DDL. Most of the SQL based DBMS products support these three SQL verbs that are
- CREATE used to create database and tables.
- DROP used to drop the tables as well as databases.
- ALTER used to change the structure of the tables.
This statement is used to create the new database.
Syntax CREATE DATABASE database-name;Note. If you want to create new database, first you will get the administrator privileges. Otherwise you don't allow to create a database.
Example SQL query: Here we create a database as collegeDB
mysql> CREATE DATABASE collegeDB; Query OK, 1 row affected (0.31 sec)
Once database is created, we can visually see it by using the 'SHOW databases' SQL statement.
mysql> SHOW databases;
The above statement will display the all databases created in the RDBMS server.
+--------------------+ | Database | +--------------------+ | collegedb | | information_schema | | mysql | | performance_schema | | sys | | world | +--------------------+ 6 rows in set (0.11 sec)
Now we are ready to use that database. Further, you can define the tables inside the selected database. 'Use database' can be used to select the specific database.
Use Database Syntax and example USE database-name; For Example: mysql> USE collegeDB; Database changed