I have a table say ITEM that should contain :
ID_SERVICE , // foreign key to table SERVICE
ID_FILE , // foreign key to table FILE
ID_FUNCTION // foreign key to table FUNCTION
and it must be identified by those 3 columns (compound primary key) , however my problem is that sometimes i might have an item that doesnt have a function (ID_FUNCTION could be null).
How can i redesign this table so that it can handle these constraintes ?
Thanks.
You create a unique index not a primary key constraint. A unique index allows for any key to be null, but still enforces uniqueness over every column. The syntax is the same as index but you add unique in front:
A unique index will automatically create a unique constraint underlying it. If you don’t want the index you could just create the constraint on it’s own:
Here is more information on the different types of constraints.