Saturday, 4 May 2013
SQL CREATE TABLE
Purpose:
This command is use for create a table file
Syntax:
CREATE TABLE table-name
Complete Syntax:
CREATE TABLE file
(column (attribute) name1 data types [PRIMARY KEY] or [FOREIGN KEY references column-name]
column (attribute) name2 data types,
.........,
……..
)
Note: Primary/Foreign key is optional. Only apply if column is set as primary /Foreign key.
Examples:
With PRIMARY KEY
CREATE TABLE student
(
sid char(5) PRIMARY KEY,
age int,
fname char(20),
lname char(20)
)
With FOREIGN KEY
CREATE TABLE register
(
sid char(12) FOREIGN KEY references student(sid),
cid char(6) FOREIGN KEY references course(cid),
PRIMARY KEY (sid,cid) or CONSTRAINT PK_anyname PRIMARY KEY (sid,cid)
)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment