Create (SQL)
A CREATE
statement in SQL creates an object inside of a relational database management system (RDBMS). The types of objects that can be created depends on which RDBMS is being used, but most support the creation TABLEs, INDEXes, USERs, and DATABASEs. Some systems (such as PostgreSQL) allow CREATE
and other DDL comands to occur inside of a transaction and thus be rolled back.
CREATE TABLE
Perhaps the most common CREATE
command is the CREATE TABLE
command. The typical usage is:
CREATE TABLE [table_name] ( [column_name type (size)] [column_name type (size)])
.
Column Defitions: A comma-separated list consisting of any of the following
- Column definition: [column name] [data type] {NULL | NOT NULL} {column options}
- Primary key definition: PRIMARY KEY ( [comma separated column list] )
- CONTRAINTS: {CONSTRAINT}} [constraint definition]
- RDBMS specific functionality
For example, the command to create a table named employees with a few sample columns would be:
CREATE TABLE employees
(empno INTEGER not null
,empfname CHAR(50) null
,emplname CHAR(75) not null
,date_of_birth DATE null
,PRIMARY KEY (empno)
);
For example, the command to create a table named teachers with a few sample columns would be:
CREATE TABLE teachers
(tno CHAR (4) not null
,tname CHAR(45) null
,taddress CHAR(65) not null
,salary NUMBER (7,2) null
,date_of_joinig DATE not null
,date_of_birth DATE null
,dept_no CHAR (4) null
,PRIMARY KEY (tno)
);