Table Creation

Below is an example of table creation with different types of data structures and relationships

-- Table Creation where:
-- MajorCode is Pirmary Key

CREATE TABLE tblMajors (
    MajorCode INT NOT NULL,
    MajorDescription VARCHAR(50),
	PRIMARY KEY (MajorCode)
); 

-- Table Creation where:
-- Different Data Types are added

CREATE TABLE tblInstructors (
	InstructorNumber INT NOT NULL,
	InstructorFirst VARCHAR(50),
	InstructorLast VARCHAR(50),
	ContractStatus NUMERIC,
	PhoneNumber NUMERIC,
	PRIMARY KEY (InstructorNumber)
);

-- Table Creation where:
-- MajorCode is Forign Key

CREATE TABLE tblStudents (
	StudentNumber INT NOT NULL,
	StudentFrist VARCHAR(50),
	StudentLast VARCHAR(50),
	MajorCode INT FOREIGN KEY REFERENCES MajorCode(MajorCode),
	PRIMARY KEY (StudentNumber)
);

-- Creating Indexes

CREATE INDEX indexStudents
ON tlbStudents (StudentLast); 

CREATE INDEX indexGrades
ON tlbGrades (StudentNuber); 

Last updated