Creating Company Database Schema and Populating With Data: and Reasoning Behind Constraints
Creating Company Database Schema and Populating With Data: and Reasoning Behind Constraints
Creating Company Database Schema and Populating With Data: and Reasoning Behind Constraints
Step 1: This involves creation of the tables. Comments have been added to indicate various data types
and reasoning behind constraints.
-- Now that the DEPARTMENT table is defined, add the Foreign Key constraints
-- to the EMPLOYEE table.
-- Super_ssn references Ssn
Step 2: Temporarily, the Foreign Key constraint between Dno and Dnumber is unchecked to allow
seeding of the database with the data provided in the assignment. Once the EMPLOYEE table is
seeded, INSERT statements are executed to populate the remaining tables in the schema. The data
mostly matches what is provided in the assignment – the date format had to be modified to YYYY-MM-
DD, and missing values were set as NULL. “USE COMPANYDB1” enables aliasing of the high level
relation qualifiers.
//disable
SET FOREIGN_KEY_CHECKS=0;
//enable
SET FOREIGN_KEY_CHECKS=1;
The data for hours for the hours domain value in the highlighted row below was missing
from the data. Since the column did not allow nulls, it has been defaulted to a zero
(0). An alternative would have been to specify a DEFAULT as 0 rather than not
allowing NULL values.
All INSERT statements ran successfully – all tables are verified for data.
USE COMPANYDB1;
select * from DEPARTMENT;
select * from DEPENDENT;
select * from
DEPT_LOCATIONS; select *
From EMPLOYEE;
select * from PROJECT;
select * from
WORKS_ON;