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.
Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example…
Given an integer A. Compute and return the square root of A. If A is…
Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…
A heap is a specialized tree-based data structure that satisfies the heap property. It is…
What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…