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 NOT NULL,
courseName VARCHAR NOT NULL UNIQUE,
credits DECIMAL CHECK credits AND credits NOT NULL,
courseDescription VARCHAR
PRIMARY KEY courseNum
;
Created COURSEOFFER table with composite primary key
CREATE TABLE COURSEOFFER
courseNum CHAR NOT NULL,
Subject CHAR NOT NULL,
CourseName VARCHAR NOT NULL,
section CHAR NOT NULL,
startRegistration DATE NOT NULL,
enrollCap INT CHECK enrollCap
PRIMARY KEY courseNum Subject, section
;
Created EMPLOYEE table with primary key and unique constraint
CREATE TABLE EMPLOYEE
empID CHAR NOT NULL,
lastName VARCHAR NOT NULL,
firstName VARCHAR NOT NULL,
ssn CHAR NOT NULL UNIQUE,
PRIMARY KEY empID
;
Added Primary Key to an existing table MAJOR
ALTER TABLE MAJOR
ADD CONSTRAINT PKMAJOR PRIMARY KEY MajorCode;
Create composite primary key for CLASS table
ALTER TABLE CLASS
ADD CONSTRAINT PKCLASS 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 PKCOURSEOFFER PRIMARY KEY courseNum Subject, Section;
Add Foreign Key to STUDENT table referencing MAJOR
ALTER TABLE STUDENT
ADD CONSTRAINT FKSTUDMAJOR FOREIGN KEY MajorCode REFERENCES MAJORMajorCode;
Add composite Foreign Key to CARREGISTER table referencing DRIVER
ALTER TABLE CARREGISTER
ADD CONSTRAINT FKCARREGDRIVER FOREIGN KEY Pid DL REFERENCES DRIVERPersonID DriverLicense;
Add composite Foreign Key to CLASSREG table referencing COURSEOFFER
ALTER TABLE CLASSREG
ADD CONSTRAINT FKCLASSREGCOURSEOFFER FOREIGN KEY cNo Subj, Sec REFERENCES COURSEOFFERcourseNum Subject, Section;
Add two Foreign Keys to CLASSREG table
ALTER TABLE CLASSREG
ADD CONSTRAINT FKCLASSREGCOURSEOFFER FOREIGN KEY cNo Subj, Sec REFERENCES COURSEOFFERcourseNum Subject, Section
ADD CONSTRAINT FKCLASSREGSTUDENT FOREIGN KEY gNum REFERENCES STUDENTgNumber;
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 notnull 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 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
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
