70 likes | 172 Views
Recap of SQL. Lab no. 7 Advance Database Management System. Lab Outline. Recap of SQL CREATE TABLE command. CREATE Command. CREATE TABLE <table name> (<column specification> , <column specification>… ). CREATE Command. <table name> It is the name of the table being created
E N D
Recap of SQL Lab no. 7 Advance Database Management System
Lab Outline • Recap of SQL • CREATE TABLE command
CREATE Command • CREATE TABLE <table name> (<column specification> , <column specification>… )
CREATE Command • <table name> • It is the name of the table being created • <column specification> • It is the specification of a column • It consists of • Column name • Column data type • Size (length) associated with data type • Columns can be key or non key columns • Key columns are PKs or FKs and have a special ‘constraint’ tag specified in their definition
Example CREATE TABLE Course ( CourseID CHAR(6) NOT NULL, CourseDsc VARCHAR(50) CONSTRAINT PK_1 PRIMARY KEY(CourseID), CONSTRAINT U_1 UNIQUE(CourseDsc) )
Example • The following slides show CREATE TABLE command examples. • The first one shows creation of a table named ‘Course’. • The second example shows creation of a table ‘StudentCourse’ which takes FKs from ‘Course’ and another table ‘Student’ • PK and FK definitions are elaborated in the examples.
Example CREATE TABLE StudentCourse ( StdID VARCHAR(10) NOT NULL, CourseID CHAR(6) NOT NULL, CourseDsc VARCHAR(50) CONSTRAINT PK_1 PRIMARY KEY(CourseID), CONSTRAINT U_1 UNIQUE(CourseDsc), CONSTRAINT FK_1 FOREIGN KEY(StdID) REFERENCES Student, CONSTRAINT FK_2 FOREIGN KEY(CourseID) REFERENCES Course )