Creation and deletion of a database

Creation and deletion of a database

Creation of a database

The CREATE DATABASE statement is used to create a new SQL database.

Syntax :
                                CREATE DATABASE databaseName;
                            

The database name must always be unique in the RDBMS.

Example :

If you want to create a new database "csteachers", the CREATE DATABASE statement will be as below.

                                CREATE DATABASE csteachers;
                            

Make sure you have administrator privilege before creating a database.
Once the database is created, you can check it as follows in the list of databases.

                                SHOW DATABASES;
                            

Delete a database

The DROP DATABASE statement is used to drop an existing database from an SQL schema.

Syntax :
                                DROP DATABASE databaseName;
                            
Example :

If you want to delete an existing database "csteachers", the DROP DATABASE statement will be as below.

                                DROP DATABASE csteachers;
                            
Notes ! Be careful before using this operation, since deleting an existing database would result in the loss of the complete information stored in the database.

Make sure you have administrator privilege before deleting a database. Once a database is deleted, you can check if it still exist in the list of databases, as shown below.

                                SHOW DATABASES;
                            

Select a database

When you have several databases in your SQL schema, before starting your operation, you must select a database on which all the operations will be performed.

Use the USE statement to select an existing database in the SQL schema.

Syntax :
                                USE databaseName;
                            
Example :

If you want to use the database csteachers, you can run the following SQL command and start using the devInfo database.

                                Use csteachers;
                            

Share this course with your friends :

This course is written by M. ESSADDOUKI Mostafa

Many people realize their hearts desires late in life. Continue learning, never stop striving and keep your curiosity sharp, and you will never become too old to appreciate life.

0 Comment(s)

To leave a comment you must have an account Sign up, or Sign in