SQL中的限制 [英] Restrictions in SQL

查看:63
本文介绍了SQL中的限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好...我创建了一个基于DotNet的项目...在VS 2005上实现.我的项目基于医院管理系统..在我的情况下,我使用的数据库是SQL Server 2005.该项目很好...但是我只想在我的项目中实现一个新事物...即...我只希望我的项目在数据库(SQL)中仅存储50条记录..如果用户存储了第51条记录..然后必须显示错误..座位不可用.

因此,SQL中是否有任何命令...可用来限制用户不超过第50条记录.

请帮我解决上述问题...如果可能,请向我提供有用的声明或编码.

谢谢.

Prateek

Hey guys...i have created a project based on DotNet...implemented on VS 2005. My project is based on the hospital management system..and database in my case i have used is SQL server 2005. Everything is fine with the project...but i just want to implement one(new) thing in my project...that is...I just want my project to store only 50 records in the database(SQL)..and if a user stores the 51th record..then the error must be shown..that seates are not available.

So is there any command in SQL...by which we can restrict the user to not to exceed beyond the 50th record.

Plz help me regarding the above mentioned issue...and ifpossible provide me with the usefull statements or coding.

Thanx.

Prateek

推荐答案

您想要将试用版软件分发给客户端进行演示的声音.好的,您可以通过两种方式实现您的要求.
在前端或后端.

只需编写一个函数即可查找表的记录计数(在项目中使用的记录)
在C#中:
Sounds like you want to distribute your trial software to clients for demo. Ok you can implement your requirement by two ways.
In, Front end or back end.

Just write a funtion for find a record count of your Table (Which is using in your project)
In C#:
public int GetRecordCount()
{
   // Code to be write
   return 50;
}


每次插入新记录之前,请检查此功能值.


Check this funtion value before you insert a new record every time.

public void InsertNewRecord()
{
   if(GetRecordCount()>50)
   {
       Messagebox.Show("Trial expired, You can enter only 50 records");
   }
   else
   {
      //Code for Insert a new record
   }
}


在SQL中:


In SQL:

CREATE PROCEDURE [GetRecordCount]
(
    
)
AS
BEGIN
SET NOCOUNT ON;
    SELECT Count(*) FROM [Table_Name]
    --Where [Condition]
SET NOCOUNT OFF;
END


您可以从此存储过程中获取记录计数,每次都与该C#代码相同地检查此sp.

最终在部署时对存储过程进行加密.


You can get the record count from this stored procedure, check this sp every time same as that c# code.

Finally encrypt your stored procedure while deployment.


这篇关于SQL中的限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆