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?
CodePudding user response:
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.