The SQL CREATE command is a type of DDL command that is primarily used for creating databases and tables. To create databases or tables with the desired structure, the CREATE command has a specific syntax that must be followed.
Before we can perform any other functions, we must first create a database, which is the first step in learning SQL.
CREATE Database db_name;
where db_name is the name of the database.
CREATE table table_name
(
column1 datatype (size),
column2 datatype (size),
.
.
columnN datatype(size)
);
where table_name is name of the table, and column is the name of the column.
CREATE TABLE SCHOOL;
Here we have created a database SCHOOL.
The following code block is an example, which creates a STUDENT table with a ROLL as a primary key and NOT NULL are the constraints showing that these fields cannot be NULL while creating records in this table −
CREATE TABLE STUDENT(
ROLL INT NOT NULL,
NAME VARCHAR (20) NOT NULL,
CONTACT BIGINT NOT NULL,
ADDRESS CHAR (25) ,
PRIMARY KEY (ID)
);
Note: We can check if your table was successfully created by looking at the message displayed by the SQL server, or using the DESC command as shown below.
DESC STUDENT;
Output:
+---------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+---------------+------+-----+---------+-------+
| ROLL | int(5) | NO | PRI | | |
| NAME | varchar(20) | NO | | | |
| CONTACT | bigint(10) | NO | | | |
| ADDRESS | char(25) | YES | | NULL | |
+---------+---------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
Note: also read about Introduction to SQL
Please follow me to read my latest post on programming and technology if you like my post.
https://www.instagram.com/coderz.py/
https://www.facebook.com/coderz.py
Staying up to the mark is what defines me. Hi all! I’m Rabecca Fatima a keen learner, great enthusiast, ready to take new challenges as stepping stones towards flying colors.
Find the length of the longest absolute path to a file within the abstracted file…
You manage an e-commerce website and need to keep track of the last N order…
You are given a stream of elements that is too large to fit into memory.…
The formula for the area of a circle is given by πr². Use the Monte…
Given an integer k and a string s, write a function to determine the length…
There is a staircase with N steps, and you can ascend either 1 step or…