SQL – CREATE TABLE
SQL Create Table Syntax is used to create a table in database .
Tables are collection of rows & columns.
SQL – CREATE TABLE Syntax
CREATE TABLE Table_Name
(
ColumnName1 datatype,
ColumnName2 datatype,
ColumnName3 datatype,
….
….
….
(
ColumnName1 datatype,
ColumnName2 datatype,
ColumnName3 datatype,
….
….
….
);
ColumnName1, ColumnName2, ColumnName3, .. are name of columns.
datatype specifies the type of data to be stored in that column example : integer, variable , text or decimal etc..
SQL – CREATE TABLE Example
Example
CREATE TABLE Users
(
ID int,
Name varchar(100),
Email varchar(100),
Address varchar(100),
City varchar(100),
PRIMARY KEY (ID)
);
(
ID int,
Name varchar(100),
Email varchar(100),
Address varchar(100),
City varchar(100),
PRIMARY KEY (ID)
);
* PRIMARY KEY : Primary creates constraint on the column ID which will contain unique & not null values. We will Explain it in later topics.
Users Table will be created in CustomersDb.
To Verify the table Creation Use The following Command .
DESC TableName;
Example
DESC Users;
Which will Display Created table AS :
Advertisements
Add Comment
📖 Read More
- 1. SQL - INSERT
- 2. SQL - SELECT
- 3. SQL - WHERE Clause
- 4. SQL - AND & OR
- 5. SQL ORDER BY
- 6. SQL - UPDATE
- 7. SQL - DELETE
- 8. SQL - Like
- 9. SQL In Operator
- 10. SQL Between