SQL Create Database | SQL Drop & Select Database

1. Objective

In this SQL tutorial, we are going to learn about the SQL Create Database. Moreover, we will also see the SQL drop and select database. Here, we will see syntax and example of SQL Create Database, SQL Drop database, SQL Select Database.
So, let’s start with the SQL Create Database.

SQL Create Database

SQL Create Database | SQL Drop & Select Database

2. SQL Create Database

The CREATE table statement is used to create tables in SQL, additionally, existing tables can also be created for a combination with a SELECT statement. _
Do you Know about SQL Operators
Syntax of SQL Create Database–

CREATE TABLE table_name(
  column1 datatype,
  column2 datatype,
  column3 datatype,
  .....
  columnN datatype,
  PRIMARY KEY( one or more columns )
);

Example of SQL Create Database –
In this example, a database is created named CUSTOMERS table with an ID as a primary key and NOT NULL are the constraints showing that these fields cannot be NULL while creating records in this table-

SQL> CREATE TABLE CUSTOMERS(
  ID  INT            NOT NULL,
  NAME VARCHAR (20)     NOT NULL,
  AGE  INT            NOT NULL,
  ADDRESS  CHAR (25) ,
  SALARY   DECIMAL (18, 2),
  PRIMARY KEY (ID)
);
SQL> DESC CUSTOMERS;

+———+—————+——+—–+———+——-+
| Field   | Type      | Null | Key | Default | Extra |
+———+—————+——+—–+———+——-+
| ID      | int(11)      | NO | PRI |       | |
| NAME    | varchar(20)   | NO | |       | |
| AGE     | int(11)      | NO | |       | |
| ADDRESS | char(25)      | YES | | NULL |     |
| SALARY  | decimal(18,2) | YES  | | NULL | |
+———+—————+——+—–+———+——-+
5 rows in set (0.00 sec)

3. SQL Drop Database

The DROP TABLE statement is employed to drop an existing table in a database.
Syntax of SQL Drop Database – 

DROP TABLE table_name;

SQL DROP TABLE Example
The following SQL statement drops the existing table “Shippers”:
Example of SQL Drop Database – 

DROP TABLE Shippers;

The SQL DROP database statement is used to drop an existing database in SQL schema.
If you want to delete an existing information, then the DROP database statement would be as shown below −
Have a look at SQL RDBMS Concept 

SQL> DROP database testDB;

NOTE − be careful before using this operation as a result of by deleting an existing database would lead to loss of complete information stored in the database.

SQL> SHOW DATABASES;

+——————–+
| database |
+——————–+
| information_schema |
| AMROOD |
| TUTORIALSPOINT |
| mysql |
| orig |
| take a look at |
+——————–+
6 rows in set (0.00 sec)

4. SQL Select Database

A SELECT statement is used to select multiple numbers of databases to perform various operations on them. The USE statement is used to select an already existing database.
The syntax of SQL Select Database – 
The basic syntax of the USE statement is as shown below −
Let’s discuss SQL RDBMS database

USE DatabaseName;

Always the database name should be unique within the RDBMS.
Example of SQL Select Database- 
You can check the available databases as shown below −

SQL> SHOW DATABASES;

+——————–+
| Database           |
+——————–+
| information_schema |
| AMROOD             |
| TUTORIALSPOINT     |
| mysql              |
| orig               |
| test               |
+——————–+
6 rows in set (0.00 sec)
So, this was all about SQL Create database statement. Hope you like our explanation of SQL Select and Drop database.

5. Conclusion

In this SQL Create Database tutorial, we learned about the various statements such as CREATE, SELECT and DROP statement in SQL. Moreover, we also saw syntax and example of SQL Create Database, SQL Select Database, SQL Drop database. Still, if any doubt regarding SQL Create Database, ask in the comment tab.
For reference

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.