Reputation: 501
I have a table that has 3 columns (id, name, orgId(foreign key) What I am trying to achieve is to have the column name unique if only the orgId matches
How do I define the schema?
Upvotes: 0
Views: 175
Reputation: 246493
That would be a unique constraint defined on both columns:
ALTER TABLE tab ADD UNIQUE (orgid, name);
That will exclude only rows where both name
and orgid
are identical to an already existing row.
Upvotes: 1