0% found this document useful (0 votes)
4 views3 pages

Database Management System Lecture 03 SQL Commands For ER Lect1

The document outlines the creation of three database tables: Instructor, Student, and Advisor, which establish a many-to-many relationship between students and instructors. It includes SQL commands for creating the tables and inserting sample data, detailing the structure and relationships, including primary and foreign keys. Additionally, it provides a brief explanation of the advising relationships and sample data entries for instructors and students.

Uploaded by

ridwan.rafi01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Database Management System Lecture 03 SQL Commands For ER Lect1

The document outlines the creation of three database tables: Instructor, Student, and Advisor, which establish a many-to-many relationship between students and instructors. It includes SQL commands for creating the tables and inserting sample data, detailing the structure and relationships, including primary and foreign keys. Additionally, it provides a brief explanation of the advising relationships and sample data entries for instructors and students.

Uploaded by

ridwan.rafi01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

-- Create the Instructor table

CREATE TABLE Instructor (


ID INT PRIMARY KEY,
Name VARCHAR(100),
Salary DECIMAL(10, 2)
);

-- Create the Student table


CREATE TABLE Student (
ID INT PRIMARY KEY,
Name VARCHAR(100),
Tot_Credits INT
);

-- Create the Advisor relationship table


CREATE TABLE Advisor (
Student_ID INT,
Instructor_ID INT,
DateAssigned DATE,
PRIMARY KEY (Student_ID, Instructor_ID),
FOREIGN KEY (Student_ID) REFERENCES Student(ID),
FOREIGN KEY (Instructor_ID) REFERENCES Instructor(ID)
);

Explanation

●​ Instructor(ID, Name, Salary) stores instructor details.​

●​ Student(ID, Name, Tot_Credits) stores student details.​

●​ Advisor(Student_ID, Instructor_ID, DateAssigned):​

○​ Establishes a many-to-many relationship (a student can have multiple advisors


and vice versa).​

○​ DateAssigned records when the advising relationship was established.​

○​ Composite primary key on (Student_ID, Instructor_ID) ensures


uniqueness.​

○​ Foreign keys maintain referential integrity.


Here's how you can insert sample data into the Instructor, Student, and Advisor tables
after creating them.

Insert Instructors

INSERT INTO Instructor (ID, Name, Salary) VALUES

(101, 'Dr. Alice Smith', 90000.00),

(102, 'Dr. Bob Johnson', 85000.00),

(103, 'Dr. Carol Lee', 92000.00);

Insert Students

INSERT INTO Student (ID, Name, Tot_Credits) VALUES

(201, 'Emma Brown', 45),

(202, 'Liam Wilson', 60),

(203, 'Noah Davis', 30);


Insert Advisor Relationships

INSERT INTO Advisor (Student_ID, Instructor_ID, DateAssigned) VALUES

(201, 101, '2025-01-10'),

(202, 102, '2025-02-05'),

(203, 101, '2025-01-22'),

(202, 103, '2025-03-01'); -- Liam has two advisors

Notes

●​ Dates are in YYYY-MM-DD format.​

●​ In this setup:​

○​ Emma is advised by Alice​

○​ Liam is advised by both Bob and Carol​

○​ Noah is advised by Alice

You might also like