To learn more about what SQL is, readers can refer to the article SQL What is Taimienphi.vn. The following article will only revolve around the contents of the CREATE command in SQL.
CREATE statement in SQL
In SQL there are 2 commands CREATE Available, including:
– CREATE DATABASE
– CREATE TABLE
CREATE DATABASE command in SQL
Database (SQL) in SQL is defined as a sorted data set. So in SQL, the first step to storing sorted data is to create a database. The CREATE DATABASE command is used to create a new database in SQL.
CREATE DATABASE database_name;
database_name: name of the database.
This query will create a new database in SQL and name the database my_database:
CREATE DATABASE my_database;
The CREATE TABLE statement in SQL
As Taimienphi.vn mentioned above, the CREATE DATABASE command is used to create a new database in SQL. To store data in SQL, you need to have 1 data table. The CREATE TABLE statement is used to create a table in SQL.
A table consists of rows and columns. So while creating the table, you must provide information for SQL including the column name, the type of data stored in the column, the size of the data.
Below is the syntax of the CREATE TABLE statement to create a table in SQL.
CREATE TABLE table_name
column1 data_type (size),
column2 data_type (size),
column3 data_type (size),
table_name: name of the table.
column1: The name of the first column.
data_type: The type of data you want to store in specific column. For example, int for integer data.
– Size: The size of the data we can store in specific columns. For example, if the data_type column is defined as int and the size is 10, then this column can store an integer, up to 10 digits.
The following query creates a table named Students, consisting of 3 columns ROLL_NO, NAME and SUBJECT:
CREATE TABLE Students
ROLL_NO int (3),
NAME varchar (20),
SUBJECT varchar (20),
The above query will create the Students table. The ROLL_NO frame is of type int and can store integers with a size of 3. The next 2 columns are NAME and SUBJECT is of type varchar, can store characters and size 20 i.e. these frames can contain up to up to 20 characters.
The above article Taimienphi.vn has just introduced you to the CREATE command in SQL. Basically, there are 2 CREATE statements in SQL, including the CREATE DATABASE and CREATE TABLE statements. The next article Taimienphi.vn will introduce you further DELETE statement in SQL.
If you have any questions or need any answers, please leave your comments in the comment section below the article, Taimienphi.vn will answer your questions as soon as possible.