Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/ * Company database mySQL data definition. Ordering of tables is important since a table can reference tables that are defined before. Since date type
Company database mySQL data definition.
Ordering of tables is important
since a table can reference tables that are defined before.
Since date type is not available in MySQL
create a new user defined data type date as char
Phase : Drop all six tables of Company database if they exist
in the correct sequence without violating foreign key constraints
if dependent table already exists, remove the table
drop table if exists dependent;
if workson table already exists, remove the tablema
drop table if exists workson;
if project table already exists, remove the table
drop table if exists project;
if deptlocations table already exists, remove the table
drop table if exists deptlocations;
if employee table already exists, remove the table
drop table if exists employee;
if department table already exists,department remove the table
drop table if exists department;
Phase : Create all six empty tables of Company database
create a new empty table department
create table department
dname varchar not null,
dnumber int not null,
mgrssn char not null,
mgrstartdate char
constraint deptpk
primary key dnumber
constraint deptsk
unique dname
constraint deptmgrfk
foreign key mgrssn references employeessn
This foreign key has been commented out since the dbms does not
support mutual foreign keys between department and employee tables
;
create a new empty table employee
create table employee
fname varchar not null,
minit char,
lname varchar not null,
ssn char not null,
bdate char
address varchar
sex char,
salary decimal
superssn char
dno int not null,
constraint emppk
primary key ssn
constraint empsuperfk
foreign key superssn references employeessn
This foreign key constraint among columns of the same table
has not been supported by MSSQL
constraint empdeptfk
foreign key dno references departmentdnumber
;
create a new empty table deptlocations
create table deptlocations
dnumber int not null,
dlocation varchar not null,
constraint dlocpk
primary key dnumber dlocation
constraint dlocdeptfk
foreign key dnumber references departmentdnumber
;
create a new empty table project
create table project
pname varchar not null,
pnumber int not null,
plocation varchar
dnum int not null,
constraint projpk
primary key pnumber
constraint projsk
unique pname
constraint projdeptfk
foreign key dnum references departmentdnumber
;
create a new empty table workson
create table workson
essn char not null,
pno int not null,
hours decimal not null,
constraint workpk
primary key essn pno
constraint workempfk
foreign key essn references employeessn
constraint workprojfk
foreign key pno references projectpnumber
;
create a new empty table dependent
create table dependent
essn char not null,
dependentname varchar not null,
sex char,
bdate char
relationship varchar
constraint deppk
primary key essn dependentname
constraint depempfk
foreign key essn references employeessn
;
Phase : Add rows of data to each of these six empty tables of Company DB
Insertion of three department rows
INSERT INTO department
VALUES
Research;
INSERT INTO department
VALUES
Administration;
INSERT INTO department
VALUES
Headquarters;
Insertion of eight employee rows
INSERT INTO employee
VALUES
JamesE'Borg', Stone, Houston, TXM;
INSERT INTO employee
VALUES
FranklinT'Wong', Voss, Houston, TXM;
INSERT INTO employee
VALUES
JenniferS'Wallace', Berry, Bellaire, TXF;
INSERT INTO employee
VALUES
JohnB'Smith', Fondren, Houston, TXM;
INSERT INTO employee
VALUES
RameshK'Narayan', Fire Oak, Humble, TXM;
INSERT INTO employee
VALUES
JoyceA'English', Rice, Houston, TXF;
INSERT INTO employee
VALUES
AliciaJ'Zelaya', Castle, Spring, TXF;
INSERT INTO employee
VALUES
AhmadV'Jabbar', Dallas, Houston, TXM;
Insertion of five deptlocations rows
INSERT INTO deptlocations
VALUES
'Houston';
INSERT INTO deptlocations
VALUES
'Stafford';
INSERT INTO deptlocations
VALUES
'Bellaire';
INSERT INTO deptlocations
VALUES
'Sugarl
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started