In: Computer Science
Consider the following SQL DDL statements:
CREATE TABLE DEPT ( did INTEGER,
dname VARCHAR(20),
PRIMARY KEY(did));
CREATE TABLE EMP( eid INTEGER,
name VARCHAR(20),
did INTEGER,
PRIMARY KEY(eid),
FOREIGN KEY(did) REFERENCES DEPT);
In the database created by above statements, which of the following
operations may cause violation
of referential integrity constraints?
Question 1 options:
UPDATE on DEPT |
|
INSERT into DEPT |
|
DELETE on EMP |
|
Both DELETE on EMP and INSERT into DEPT |
Solution
DELETE on EMP |
Explanation In the DEPT table there are no referential integrity that means no foreign key if you insert any values or update values it will not cause any violation for e.g |
as you can see we are inserting 2 new records and updating existing records in the DEPT violation there are no violation
--
but deleting a record cause referential integrity violation because
FOREIGN KEY(did) REFERENCES DEPT);
did is the foreign key
---
all the best