Question: Below is my ER model with brief comments: - - Created Database CREATE DATABASE SchoolDB; - - After creation of Database, to use it we

Below is my ER model with brief comments:
-- Created Database
CREATE DATABASE SchoolDB;
-- After creation of Database, to use it we will use the following command
USE SchoolDB;
-- Created COURSE table with primary key
CREATE TABLE COURSE(
courseNum CHAR(8) NOT NULL,
courseName VARCHAR(30) NOT NULL UNIQUE,
credits DECIMAL(3,1) CHECK (credits >0 AND credits %0.5=0) NOT NULL,
courseDescription VARCHAR(500),
PRIMARY KEY (courseNum)
);
-- Created COURSEOFFER table with composite primary key
CREATE TABLE COURSEOFFER(
courseNum CHAR(3) NOT NULL,
Subject CHAR(4) NOT NULL,
CourseName VARCHAR(30) NOT NULL,
section CHAR(3) NOT NULL,
startRegistration DATE NOT NULL,
enrollCap INT CHECK (enrollCap <=300),
PRIMARY KEY (courseNum, Subject, section)
);
-- Created EMPLOYEE table with primary key and unique constraint
CREATE TABLE EMPLOYEE(
empID CHAR(3) NOT NULL,
lastName VARCHAR(15) NOT NULL,
firstName VARCHAR(15) NOT NULL,
ssn CHAR(9) NOT NULL UNIQUE,
PRIMARY KEY (empID)
);
-- Added Primary Key to an existing table MAJOR
ALTER TABLE MAJOR
ADD CONSTRAINT PK_MAJOR PRIMARY KEY (MajorCode);
-- Create composite primary key for CLASS table
ALTER TABLE CLASS
ADD CONSTRAINT PK_CLASS PRIMARY KEY (courseNum, Dept);
-- COURSEOFFER add composite primary key
-- Note: This step might be redundant if the table is created as above with primary key
ALTER TABLE COURSEOFFER
ADD CONSTRAINT PK_COURSEOFFER PRIMARY KEY (courseNum, Subject, Section);
-- Add Foreign Key to STUDENT table referencing MAJOR
ALTER TABLE STUDENT
ADD CONSTRAINT FK_STUD_MAJOR FOREIGN KEY (MajorCode) REFERENCES MAJOR(MajorCode);
-- Add composite Foreign Key to CARREGISTER table referencing DRIVER
ALTER TABLE CARREGISTER
ADD CONSTRAINT FK_CARREG_DRIVER FOREIGN KEY (Pid, DL) REFERENCES DRIVER(PersonID, DriverLicense);
-- Add composite Foreign Key to CLASSREG table referencing COURSEOFFER
ALTER TABLE CLASSREG
ADD CONSTRAINT FK_CLASSREG_COURSEOFFER FOREIGN KEY (cNo, Subj, Sec) REFERENCES COURSEOFFER(courseNum, Subject, Section);
-- Add two Foreign Keys to CLASSREG table
ALTER TABLE CLASSREG
ADD CONSTRAINT FK_CLASSREG_COURSEOFFER FOREIGN KEY (cNo, Subj, Sec) REFERENCES COURSEOFFER(courseNum, Subject, Section),
ADD CONSTRAINT FK_CLASSREG_STUDENT FOREIGN KEY (gNum) REFERENCES STUDENT(gNumber);
The SQL script above outlines the process of setting up a database for a school management system, which involves creating a new database named SchoolDB and defining its structure through the creation of tables for courses (COURSE), course offerings (COURSEOFFER), and employees (EMPLOYEE). Each table is carefully designed with constraints to ensure data integrity, including not-null constraints, unique constraints, primary keys for identifying records uniquely, and foreign keys for establishing relationships between tables. For example, the COURSE table includes a unique course number as the primary key and constraints to ensure course names are unique and credits are in 0.5 increments. The COURSEOFFER table uses a composite primary key consisting of course number, subject, and section, and adds columns for registration start dates and enrollment caps with specific conditions. The EMPLOYEE table is structured with an employee ID as the primary key and a unique constraint on the social security number. Additionally, the script enhances existing tables with primary and foreign keys to link related data across the database, such as linking students to majors and class registrations to course offerings, thereby facilitating data consistency and referential integrity across the school management system.
Create the physical ER model using the revised tables.
Rewrite your SQL to create a new database and implement all the new tables from Step 2
Create all of the tables, attributes, and the primary and foreign keys

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!