How should I do this (business logic) in Sql Server? A constraint?
- by Pure.Krome
Hi folks,
I wish to add some type of business logic constraint to a table, but not sure how / where.
I have a table with the following fields.
ID INTEGER IDENTITY
HubId INTEGER
CategoryId INTEGER
IsFeatured BIT
Foo NVARCHAR(200)
etc.
So what i wish is that you can only have one featured thingy, per articleId + hubId.
eg.
1, 1, 1, 1, 'blah' -- Ok.
2, 1, 2, 1, 'more blah' -- Also Ok
3, 1, 1, 1, 'aaa' -- constraint error
4, 1, 1, 0, 'asdasdad' -- Ok.
5, 1, 1, 0, 'bbbb' -- Ok.
etc.
so the third row to be inserterd would fail because that hub AND category already have a featured thingy.
Is this possible?