DBMSSQL

Create Table Command

Create Table Command

Tables are defined with the create table command. Create Table command basically defines a table name describing a set of named columns in a specified order. It also defines the data types and sizes of the columns. Each table must have at least one column.

Syntax :

CREATE TABLE <TABLE NAME>
 (  
< COLUMN NAME > < DATA TYPE >
[COLUMN CONSTRAINTS], < COLUMN NAME 2 >n <DATA TYPE > 
[COLUMN CONSTRAINTS]
< COLUMN NAME N >  < DATA TYPE> 
[COLUMN CONSTRAINTS]
[TABLE CONSTRAINTS]
);

Now using create table command we will create an example table which we will be using this learn for more examples for next sections

Example.

CREATE TABLE STUDENTS
(
ROLL_NO NUMBER(5)  PRIMARY KEY,  NAME CHAR(20)  NOT NULL,  CLASS VARCHAR(25) DEFAULT(BCA),  PHONE NUMBER(10) UNIQUE 
);

Here (Roll no, Name, Class, Phone) are column names

And (NUMBER, CHAR, VARCHAR) are data types

(PRIMARY KEY, NOT NULL, DEFAULT, UNIQUE) are column constraints then comes ( (5), (20) etc.) are sizes of columns.

Learn about how to Alter a table definition click here

Related Articles

Check Also
Close
Back to top button