View the step-by-step solution to:

Question

The script of a database, called Employee Database, is provided below:

Code for Creation of Tables where

Fields and Primary

Keys are defined (Keyword CONSTRAINT):

CREATE TABLE emplevel

(LevelNo INT PRIMARY KEY,

LowSalary Decimal,

HighSalary Decimal);

CREATE TABLE position

(PositionId INT PRIMARY KEY,

PosDesc VARCHAR(20));

CREATE TABLE qualification

(QualId INT PRIMARY KEY,

QualDesc VARCHAR(20));

CREATE TABLE dept

(DeptId INT PRIMARY KEY,

DeptName VARCHAR(12) NOT NULL,

Location VARCHAR(15),

EmployeeId INT);

Code for Creation of Tables where Fields, Primary Keys,

and Foreign Keys are defined (Keyword CONSTRAINT). Note

that FOREIGN KEY also establishes referential

integrity.

CREATE TABLE employee

(EmployeeId INT PRIMARY KEY,

Lname VARCHAR(15) NOT NULL,

Fname VARCHAR(15) NOT NULL,

PositionId INT,

Supervisor INT,

HireDate DATE,

Salary Decimal,

Commission Decimal,

DeptId INT NOT NULL,

QualId INT,

CONSTRAINT employee_positionid_fk FOREIGN KEY (PositionId)

REFERENCES position (PositionId),

CONSTRAINT employee_deptid_fk FOREIGN KEY (DeptId)

REFERENCES dept (DeptId),

CONSTRAINT employee_qualid_fk FOREIGN KEY (QualId)

REFERENCES qualification (QualId)

);

CIS4600 Prof. Song

3

CREATE TABLE dependent

(EmployeeId INT PRIMARY KEY,

DependentId INT,

DepDOB DATE,

Relation VARCHAR(8),

CONSTRAINT dependent_employeeid_fk FOREIGN KEY (EmployeeId)

REFERENCES employee (EmployeeId)

);

Adding Foreign Key after creation of table [ALTER TABLE

command is used].

ALTER TABLE employee

ADD CONSTRAINT employee_supervisor_fk FOREIGN KEY(Supervisor)

REFERENCES employee(EmployeeId);


-What is the corresponding ERD for this SQL code?

Top Answer

An employee has one or many qualifications An employee belongs to one and only one... View the full answer

Capture.PNG

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question