I need some help with adding a check in one of the added columns to the existing tables. I am not sure if that will be a computed column or check constraint.
Table changes to Products table, new column is IsDefault
and existing column name is banId
. IsDefault
value is 0 but when turned to 1 is only possible for one per banId
column.
IsDefault BIT (only one per banId, default 0)
I need to add it to this code to add that one per banId
condition
ALTER TABLE [dbo].products
ADD IsDefault BIT NOT NULL
CONSTRAINT DF_products_IsDefault DEFAULT 0
ProductId banId IsDefault
-------------------------------------
1 1 0
2 1 1
3 1 0
4 2 0
5 2 0
6 2 0
7 3 1
8 4 1
9 4 0