6.3k views
1 vote
Consider the two relations with their schemas as listed below: Employee(name, empID, birthDate, gender, address, phone) TaxAccount(name, SSN, empID, federalDeductionAmt, stateDeductionAmt, ficaDeductionAmt) Constraint: TaxAccount must contain information related to all current employees only. Express the foreign key constraint in SQL.

1 Answer

7 votes

Answer:

CREATE TABLE TaxAccount (

Name int NOT NULL,

SSN int NOT NULL,

empID int FOREIGN KEY REFERENCES employee(empID),

federalDeductionAmt int NOT NULL,

stateDeductionAmt int NOT NULL,

ficaDeductionAmt int NOT NULL

);

Step-by-step explanation:

TaxAccount table will use the primary key of employees table 'empID' which will serve as foreign key in TaxAccount table.

Therefore TaxAccount table will look like this:

CREATE TABLE TaxAccount (

Name int NOT NULL,

SSN int NOT NULL,

empID int FOREIGN KEY REFERENCES employee(empID),

federalDeductionAmt int NOT NULL,

stateDeductionAmt int NOT NULL,

ficaDeductionAmt int NOT NULL

);

User Ravikt
by
7.2k points