Computer Science‎ > ‎

Databases and SQL: The Create Command - Creating Tables


These will give you an idea about the syntax and usage of the CREATE command which is used to create the tables.

PART 1:

CREATING THE TABLES for the database ‘College’.


CREATE SCHEMA College AUTHORIZATION John;

Schema elements include tables,  views, constraints. It is used to create the schema with authorization identifier ‘John’.

CREATE TABLE Student
(
SName VARCHAR(15) NOT NULL,

St_Id INT NOT NULL,

Bdate DATE NOT NULL,

Address VARCHAR(30),

Sex CHAR,

Br_No INT NOT NULL,

PRIMARY KEY(St_Id),

FOREIGN KEY (Br_No) REFERENCES Branch(BNo)

);
CREATE TABLE Branch
(
BName VARCHAR(15) NOT NULL,

BNo INT NOT NULL,

PRIMARY KEY(BNo)

);
CREATE TABLE Course
(
CName VARCHAR(15) NOT NULL,
CId INT NOT NULL,
BNo INT NOT NULL,
PRIMARY KEY(CId),
FOREIGN KEY(BNo) REFERENCES Branch(BNo)
);
CREATE TABLE Resource
(

St_Id INT NOT NULL,

CId INT NOT NULL,
No_of_Resources INT,
PRIMARY KEY(St_Id, CId),
FOREIGN KEY(St_Id) REFERENCES Student(St_Id),
FOREIGN KEY(CId) REFERENCES Course (CId));
Comments