Yaphet17
Yaphet17

Reputation: 135

How can I create a constraint that checks the uniquiness of the association of two columns

In MySQL database I have a table called Course which have classroom and timeslot columns so I want to create a constraint that checks no two course can have the same association of classroom and timeslot. any help is appreciated.

Upvotes: 0

Views: 22

Answers (1)

flwd
flwd

Reputation: 613

You can create a unique constraint with multiple columns like this:

ALTER TABLE Course ADD UNIQUE unique_classroom_time (classroom, timeslot);

Upvotes: 1

Related Questions