0% found this document useful (0 votes)
41 views6 pages

Section One PROJECT ANSWER

Uploaded by

Esubalew
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)
41 views6 pages

Section One PROJECT ANSWER

Uploaded by

Esubalew
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/ 6

Part 1: Database Design

Task 1: Entity-Relationship Diagram (ERD)

Entities and Relationships:

 Student (SID, fname, lname, sname, sex, age, course_code)


 Instructor (i_ID, fname, lname, sex, salary)
 Course (course_code, course_name, cr_hr, Dnumber)
 Department (Dnumber, Dname, Mgr, Locations)

Relationships:

 Student and Course: Many-to-Many (Students enroll in multiple courses; courses


have multiple students)
 Instructor and Course: Many-to-Many (Instructors teach multiple courses; each
course may be taught by multiple instructors)
 Course and Department: Many-to-One (Each course belongs to one department)

You should use a tool like VISIO, LUCIDCHART, or any ERD-specific tool to draw this
diagram.

Part 2: Database Implementation

Task 2: Create Database

CREATE DATABASE CTC;

Task 3: Create Tables

USE CTC;

-- Creating the Department table


CREATE TABLE Department (
Dnumber INT PRIMARY KEY,
Dname VARCHAR(100),
Mgr VARCHAR(100),
Locations VARCHAR(255)
);

-- Creating the Instructor table


CREATE TABLE Instructor (
i_ID INT PRIMARY KEY,
fname VARCHAR(50),
lname VARCHAR(50),
sex CHAR(1),
salary DECIMAL(10, 2)
);

-- Creating the Course table


CREATE TABLE Course (
course_code CHAR(10) PRIMARY KEY,
course_name VARCHAR(100),
cr_hr INT,
Dnumber INT,
FOREIGN KEY (Dnumber) REFERENCES Department(Dnumber)
);

-- Creating the Student table


CREATE TABLE Student (
SID CHAR(10) PRIMARY KEY,
fname VARCHAR(50),
lname VARCHAR(50),
sname VARCHAR(50),
sex CHAR(1),
age INT,
course_code CHAR(10),
FOREIGN KEY (course_code) REFERENCES Course(course_code)
);

-- Creating the relationship table for students and courses (many-to-many)


CREATE TABLE Student_Course (
SID CHAR(10),
course_code CHAR(10),
PRIMARY KEY (SID, course_code),
FOREIGN KEY (SID) REFERENCES Student(SID),
FOREIGN KEY (course_code) REFERENCES Course(course_code)
);

-- Creating the relationship table for instructors and courses (many-to-many)


CREATE TABLE Instructor_Course (
i_ID INT,
course_code CHAR(10),
PRIMARY KEY (i_ID, course_code),
FOREIGN KEY (i_ID) REFERENCES Instructor(i_ID),
FOREIGN KEY (course_code) REFERENCES Course(course_code)
);

Task 4: Insert Sample Data

-- Inserting into Department


INSERT INTO Department VALUES (1, 'Computer Science', 'Dr. Smith', 'Main
Campus');
INSERT INTO Department VALUES (2, 'Mathematics', 'Dr. Johnson', 'North Campus');

-- Inserting into Instructor


INSERT INTO Instructor VALUES (1001, 'John', 'Doe', 'M', 50000);
INSERT INTO Instructor VALUES (1002, 'Jane', 'Smith', 'F', 60000);

-- Inserting into Course


INSERT INTO Course VALUES ('CS101', 'Introduction to Programming', 4, 1);
INSERT INTO Course VALUES ('MATH201', 'Calculus II', 3, 2);

-- Inserting into Student


INSERT INTO Student VALUES ('S001', 'Alice', 'Brown', 'Brown', 'F', 22, 'CS101');
INSERT INTO Student VALUES ('S002', 'Bob', 'Dylan', 'Dylan', 'M', 24, 'MATH201');

-- Inserting into Student_Course


INSERT INTO Student_Course VALUES ('S001', 'CS101');
INSERT INTO Student_Course VALUES ('S002', 'MATH201');

-- Inserting into Instructor_Course


INSERT INTO Instructor_Course VALUES (1001, 'CS101');
INSERT INTO Instructor_Course VALUES (1002, 'MATH201');

Part 3: Data Manipulation and Queries

Task 5: Retrieve Female Students

SELECT * FROM Student WHERE sex = 'F';

Task 6: Filter Students by Last Name

SELECT * FROM Student WHERE lname LIKE 'D%n';

Task 7: Filter Students by Age

 Explanation: Retrieve all students younger than 30.


SELECT * FROM Student WHERE age < 30;

Task 8: Update Student Information

UPDATE Student SET sname = 'Awoke' WHERE SID = 'S001';

Task 9: Modify Student Table Schema

ALTER TABLE Student DROP COLUMN age;

Task 10: Add New Column to Instructor Table

ALTER TABLE Instructor ADD phone VARCHAR(15);

Task 11: Delete Instructor Record

DELETE FROM Instructor WHERE i_ID = 1002;

Task 12: Select Specific Instructor Information

SELECT i_ID, fname, lname FROM Instructor;

Task 13: Update Instructor Salary

UPDATE Instructor SET salary = salary * 1.2;

Task 14: Sort Students by Last Name

SELECT * FROM Student ORDER BY sname ASC;

Task 15: Count Gender Distribution

SELECT sex, COUNT(*) AS num_students FROM Student GROUP BY sex;

Task 16: Find Salary Extremes

SELECT MAX(salary) AS max_salary, MIN(salary) AS min_salary FROM Instructor;


Part 4: Database Maintenance

Task 17: Database Backup

For MySQL:

mysqldump -u [username] -p CTC > /path/to/MyDocuments/CTC_backup.sql

For PostgreSQL:

pg_dump CTC > /path/to/MyDocuments/CTC_backup.sql

Deliverable: Provide the SQL script or command you used for the backup and ensure the
backup file is saved correctly in the specified location.

You might also like