[英]How do i set maximum number in a table on sql database server
Please I have a SQL database project am working on and am asked to ensure that on my table HumanResources.Booking
. 请我有一个正在处理的SQL数据库项目,请确保在我的表HumanResources.Booking
。
Max_Num
should store maximum number of members allowed to use a facility at a given time Max_Num
应该存储在给定时间允许使用设施的最大成员数
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
. 其值不能超过Max_Num
的值。
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. 如果不使用trigger
或者不使用instead of trigger
(就像爱德华亲切评论的那样),这可能很难对实际表进行constraints
,这听起来像是一堆问题。 Yuck. 呸。
I would suggest the following: 我建议以下内容:
stored procedure
to do your inserts/updates 使用stored procedure
进行插入/更新 stored procedure
将问题中概述的业务逻辑放入stored 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
. 这样,你的数据应该是安全的,从那种你不想要的更新,但应用开发人员还可以就在数据库抛出他们的数据:您的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
. 请注意,如果您打算处理大量数据,则值得花费精力来优化stored procedure
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.