menu

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, 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)
);

* 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 :

SQL create table

Mysql Table

Advertisements