SQL CREATE statement

CREATE statement

To store information in a new database, use the CREATE DATABASE statement.

For the database named students, the query will be:

CREATE DATABASE students;

To organize data effectively, tables are a necessary component of the database structure.

Creating a new table

To create a table, use the CREATE TABLE statement.

CREATE TABLE students_info ( 
    student_id INT, 
    name VARCHAR(30), 
    surname VARCHAR(30), 
    age INT
);

This query creates the students_info table in the students database that will contain four columns: student_id, name, surname and age.

The student_id columnwill hold the unique student identifier of the INT type. The columns name and surname will have the VARCHAR(30) data. The age column will contain INT values.

As a result, you will get an empty table students_info:

The query above illustrates the main idea of CREATE statement implementation. The table created this way will be effortless.

Drop a database

To delete a database, you can use the DROP DATABASE statement.

The following SQL query drops the existing students database:

DROP DATABASE students;

Dropping a database will result in losing all the tables stored in it.

Drop a table

To delete only a specific table, use the DROP TABLE statement.

To delete the students_info table write the following SQL query:

DROP TABLE students_info;

While the DROP DATABASE statement deletes all the tables inside the database, the DROP TABLE statement deletes the table itself and all information stored in it.

Create a free account to access the full topic

“It has all the necessary theory, lots of practice, and projects of different levels. I haven't skipped any of the 3000+ coding exercises.”
Andrei Maftei
Hyperskill Graduate