SQL Foreign Key

1.What will be the output of below code?
CREATE TABLE dept ( dept_id INT PRIMARY KEY ); CREATE TABLE emp ( emp_id INT, dept_id INT, FOREIGN KEY (dept_id) REFERENCES dept(dept_id) ); INSERT INTO emp VALUES (101, 5);
  • A. Row inserted
  • B. Error: dept_id not found
  • C. dept_id auto-added
  • D. NULL inserted

Error: dept_id not found

Error: dept_id not found

2.What will happen?
INSERT INTO dept VALUES (10); INSERT INTO emp VALUES (201, 10);
  • A. emp row inserted
  • B. Error
  • C. dept_id becomes NULL
  • D. Duplicate entry

emp row inserted

emp row inserted

3.What is the main role of a FOREIGN KEY?
  • A. Uniquely identify records
  • B. Link tables together
  • C. Create backups
  • D. Auto-update values

Link tables together

Link tables together

4.Which table contains the FOREIGN KEY?
  • A. Parent table
  • B. Reference table
  • C. Child table
  • D. Master table

Child table

Child table

5.Can a FOREIGN KEY reference a non-primary unique key?
  • A. Yes
  • B. No

Yes

Yes