0% found this document useful (0 votes)
9 views4 pages

Dbms

The document outlines the creation of several database tables for a student enrollment system, including Students, Courses, Enrollment, Instructors, and StudentContact tables, adhering to different normalization forms. It includes SQL commands for creating these tables, inserting data, and retrieving student enrollment details. The structure ensures referential integrity through foreign key constraints.

Uploaded by

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

Dbms

The document outlines the creation of several database tables for a student enrollment system, including Students, Courses, Enrollment, Instructors, and StudentContact tables, adhering to different normalization forms. It includes SQL commands for creating these tables, inserting data, and retrieving student enrollment details. The structure ensures referential integrity through foreign key constraints.

Uploaded by

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

PROGRM 6

-- Creating Students Table (1NF)

CREATE TABLE Students2 (

StudentID INT PRIMARY KEY,

StudentName VARCHAR2(100) NOT NULL,

Phone VARCHAR2(20) UNIQUE NOT NULL

);

-- Creating Courses Table (1NF)

CREATE TABLE Courses (

CourseID INT PRIMARY KEY,

CourseName VARCHAR2(100) NOT NULL,

Instructor VARCHAR2(100) NOT NULL

);

-- Creating Enrollment Table (1NF)

CREATE TABLE Enrollment1 (

EnrollmentID INT PRIMARY KEY,

StudentID INT,

CourseID INT,

FOREIGN KEY (StudentID) REFERENCES Students2(StudentID),

FOREIGN KEY (CourseID) REFERENCES Courses(CourseID)

);

-- Creating Instructors Table (2NF)

CREATE TABLE Instructors (

InstructorID INT PRIMARY KEY,

InstructorName VARCHAR2(100) NOT NULL

);

-- Modify Courses Table to reference Instructors


ALTER TABLE Courses ADD InstructorID INT;

ALTER TABLE Courses ADD CONSTRAINT fk_instructor FOREIGN KEY (InstructorID) REFERENCES
Instructors(InstructorID);

-- Creating StudentContact Table (3NF)

CREATE TABLE StudentContact (

ContactID INT PRIMARY KEY,

StudentID INT,

Phone VARCHAR2(20) NOT NULL,

FOREIGN KEY (StudentID) REFERENCES Students2(StudentID)

);

ALTER TABLE Students2 MODIFY Phone NULL;

-- Insert Students

INSERT INTO Students2 (StudentID, StudentName) VALUES (1, 'Alice');

INSERT INTO Students2 (StudentID, StudentName) VALUES (2, 'Bob');

-- Insert Instructors

INSERT INTO Courses (CourseID, CourseName, Instructor) VALUES (102, 'Networks', 'Dr. Brown');

INSERT INTO Courses (CourseID, CourseName, Instructor) VALUES (103, 'Networks', 'Dr. Brown');

INSERT INTO Courses (CourseID, CourseName, Instructor) VALUES (112, 'graphics', 'Dr. henz’);

INSERT INTO Courses (CourseID, CourseName, Instructor) VALUES (101, 'graphics', 'Dr. henz’);

-- Insert Courses

INSERT INTO Courses (CourseID, CourseName, Instructor) VALUES (104, 'Networks', 'Dr. Brown');

INSERT INTO Courses (CourseID, CourseName, Instructor) VALUES (105, 'Networks', 'Dr. Brown');
-- Insert Enrollment Data

INSERT INTO Enrollment1 (EnrollmentID, StudentID, CourseID) VALUES (2, 1, 102);

INSERT INTO Enrollment1 (EnrollmentID, StudentID, CourseID) VALUES (3, 1, 103);

INSERT INTO Enrollment1 (EnrollmentID, StudentID, CourseID) VALUES (3, 2, 101);

-- Retrieve Student Enrollment Details

SELECT s.StudentName, c.CourseName, i.InstructorName

FROM Enrollment e

JOIN Students2 s ON e.StudentID = s.StudentID

JOIN Courses c ON e.CourseID = c.CourseID

JOIN Instructors i ON c.InstructorID = i.InstructorID;

OUTPUT

+-----------+------------+

| StudentID | Name |

+-----------+------------+

|1 | Alice |

|2 | Bob |

+-----------+------------+

+----------+-------------+

| CourseID | CourseName |

+----------+-------------+

| 101 | Database |

+----------+-------------+

+-------------+-----------+----------+
| EnrollmentID | StudentID | CourseID |

+-------------+-----------+----------+

|1 |1 | 101 |

|2 |1 | 102 |

|3 |2 | 101 |

+-------------+-----------+----------+

You might also like