SQL Create Table - The Coding Shala
Home >> Learn SQL >> SQL Create Table
Example
Other Posts You May Like
Please leave a comment below if you like this post or found some error, it will help me to improve my content.
SQL CREATE Table Statement
SQL CREATE TABLE statement is used to create new tables in the database. CREATE DATABASE statement is used to create the database. The important thing here is SQL keywords are not case sensitive means create is the same as CREATE. Below is the SQL CREATE TABLE statements and its examples are given.
CREATE DATABASE Syntax
The following is the statement is used to CREATE DATABASE -
CREATE DATABASE database_name;
SQL CREATE DATABASE Example
CREATE DATABASE mydb;
- This query will create a new database in SQL and name the database as mydb.
CREATE TABLE Syntax
The following CREATE TABLE statement is used to create tables in the database -
CREATE TABLE table_name
(
column1 datatype(size),
column2 datatype(size),
column3 datatype(size),
..
..
);
SQL CREATE TABLE Example
CREATE TABLE Persons
(
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);
- This query will create a table in the database named Persons.
- By using the 'DESC' command we can verify if the table is created or not.
Syntax
DESC table_name;
Example
> desc Persons;
Field Type Null Key Default Extra
1 PersonID int(11) YES NULL
2 LastName varchar(255) YES NULL
3 FirstName varchar(255) YES NULL
4 Address varchar(255) YES NULL
5 City varchar(255) YES NULL
Other Posts You May Like
Prev<< SQL Introduction NEXT >>SQL DROP Table
Comments
Post a Comment