Reputation: 3
Please I have a SQL database project am working on and am asked to ensure that on my table HumanResources.Booking
.
Max_Num
should store maximum number of members allowed to use a facility at a given time
Actual number should store the number of bookings already made by the members for a facility. Its value cannot exceed the value of Max_Num
.
Upvotes: 0
Views: 98
Reputation: 5274
It may be difficult to do this with constraints
on the actual table without using a trigger
or instead of trigger
(as Edward kindly commented) which just sounds like a bunch of problems down the road. Yuck.
I would suggest the following:
stored procedure
to do your inserts/updatesstored procedure
That way your data should be safe from the kind of updates you don't want, yet the application developers can still just throw their data at database: your stored procedure
. You can also then handle errors (people trying to break your business logic) nicely.
Note if you are planning on handling large amounts of data it will be well worth putting effort into optimizing your stored procedure
.
Upvotes: 1