SQL Foreign Key

6.Which keyword is used to enforce foreign key relationship?
  • A. FOREIGN JOIN
  • B. REFERENCE
  • C. REFERENCES
  • D. RELATED TO

REFERENCES

REFERENCES

7.Which of these can occur if foreign key is violated?
  • A. Row is inserted
  • B. Silent success
  • C. Error thrown
  • D. NULL inserted

Error thrown

Error thrown

8.What does ON DELETE CASCADE do?
  • A. Deletes child rows when parent is deleted
  • B. Deletes parent rows when child is deleted
  • C. Deletes all records
  • D. Ignores delete

Deletes child rows when parent is deleted

Deletes child rows when parent is deleted

9.Can FOREIGN KEY column have NULL values?
  • A. Yes
  • B. No

Yes

Yes

10.What does this line mean?
FOREIGN KEY (dept_id) REFERENCES department(id)
  • A. dept_id is a primary key
  • B. dept_id links to id in department
  • C. id is copied into dept_id
  • D. It’s a default column

dept_id links to id in department

dept_id links to id in department