0

While reading Database Systems, I have encountered through a query as shown below:

 CREATE TABLE works ( eid INTEGER NOT NULL, did INTEGER NOT NULL, pcttime INTEGER, PRIMARY KEY ( eid, did ), UNIQUE ( eid ), FOREIGN KEY ( did ) REFERENCES dept ); 

Since primary key on eid,did is already defined, why would we require unique on eid? Because each eid,did pair is already unique.

1 Answer 1

4

The primary key is on two columns, so you could still have non-unique eids. E.g.,

eid did 1 1 1 2 

This doesn't violate your primary key, but would violate your unique constraint.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the explanation!!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.