简体   繁体   English

如何在SQL数据库服务器上的表中设置最大数量

[英]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

  1. Max_Num should store maximum number of members allowed to use a facility at a given time Max_Num应该存储在给定时间允许使用设施的最大成员数

  2. 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: 我建议以下内容:

  • restrict permissions on the table so people can't insert/update the table 限制表的权限,这样人们就不能插入/更新表
  • use a stored procedure to do your inserts/updates 使用stored procedure进行插入/更新
  • put the business logic outlined in your question into the 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.

相关问题 在SQL Server数据库表中维持最大条目数的最有效方法 - Most efficient way to sustain a maximum number of entries in SQL Server database table 如何复制SQL Server数据库 - How do I copy a SQL Server database 表变量在 SQL Server 中可以拥有的最大记录数 - Maximum Number of Records a table variable can have in SQL Server 如何编写子查询以使用SQL Server数据库中的另一个表来连接姓氏和名字? - How do I write a subquery to concatenate Last name and First name using another table in database in SQL Server? 如何在SQL Server 2012 Standard Edition中压缩数据库表 - How do i compress database table in sql server 2012 Standard Edition 如何在ASP.NET Web应用程序项目中的SQL Server数据库中创建表 - How do I create a table in SQL server database in asp.net web application project 如何从SQL Server数据库表中读取元数据? - How do I read meta-data from a SQL Server database table? Sql Server中的最大记录数 - Maximum number of records in Sql Server 如何为sql server 2012中的另一个表中的每个父主键选择一个表的给定行数? - How do I select a given number of rows for one table for each parent primary key in another table in sql server 2012? 如何在数据库表的多行中添加递增数字 - How do I add an incrementing number to multiple rows in a database table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM