Question: SQL - 'Take a look at the tables below first' ----- A system must log any insertion and deletion of a project AND activity AND
SQL -
'Take a look at the tables below first'
-----A system must log any insertion and deletion of a project AND activity AND employee into their respective audit tables via TRIGGERS and must capture the data that got added or deleted, plus the operation (ADD, DELETE), date of operation, and user who performed operation---------
Create The Triggers
1) Trg_ProjectAudit: One for Project to handle Addition, Update and Deletion from the main project table (the table that contains the most fields). Audit Table name should ProjectAudit.
2) Trg_ActivityAudit: One for Activity to handle Addition, Update and Deletion from the main activity table (the table that contains the most fields). Audit Table name should ActivityAudit
3) Trg_EmployeeAudit: One for Employee to handle Addition, Update and Deletion from the main employee table (the table that contains the most fields). Audit Table name should EmployeeAudit
Tables:
Create Table Employee
(
empNumber CHAR (8) PRIMARY KEY NOT NULL,
SSN CHAR (9) NULL,
firstName VARCHAR (25) NOT NULL,
lastName VARCHAR (25) NOT NULL,
address VARCHAR (50) NULL,
state CHAR (2) NULL,
zip CHAR (5) NULL,
job VARCHAR (50) NOT NULL,
CONSTRAINT checkJob CHECK (Job IN ('Cast Member', 'Engineer', 'Inspector', 'Project Manager'))
)
Create Table Project
(
projectID char(4) PRIMARY KEY NOT NULL,
projectName VARCHAR (50) NOT NULL,
fundedBudget DECIMAL(16,2) NULL,
firmFedID CHAR(9) NOT NULL,
startDate DATE NULL,
projectTypeCode CHAR(5) NOT NULL,
projectTypeDesc VARCHAR (50) NULL,
projectStatus VARCHAR(25) NULL,
CONSTRAINT checkProjStat CHECK (projectStatus IN ('Active', 'Inactive', 'Cancelled', 'On-Hold', 'Completed')),
projectEndDate DATE NULL,
projectManager CHAR(8) FOREIGN KEY REFERENCES employee(empNumber)
)
Create Table Activity
(
activityID CHAR (4) NOT NULL PRIMARY KEY,
activityName VARCHAR (50) NOT NULL,
activityTypeCode char (2) NOT NULL,
activityStatus VARCHAR (25) NULL,
CONSTRAINT checkActStat CHECK (activityStatus IN ('Active', 'Inactive', 'Cancelled', 'On-Hold', 'Completed')),
activityTypeDesc VARCHAR (50) NULL,
costToDate DECIMAL (16,2) NULL,
startDate DATE NULL,
endDate DATE NULL,
projectID char(4) FOREIGN KEY REFERENCES Project(projectID)
)
Create Table Firm
(
firmFedID char (9) NOT NULL PRIMARY KEY,

firmName varchar (50) NOT NULL,
firmAddress varchar (50) NULL
)
Create Table Job
(
projectID char (4) NOT NULL,
activityID char (4) NOT NULL,
)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
