防止在24小时内重复记录 [英] Prevent duplication of records within 24 hours

查看:61
本文介绍了防止在24小时内重复记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想防止用户在24小时内插入相同的记录,但是在24小时后应启用插入功能,任何人都可以帮助我.
我正在使用asp.net和vb.net.
我的sqldatabase和asp.net表单上的文本框具有以下字段
ClientID,名字,姓氏,DoB
请帮助我

Please,
I want to prevent users from inserting the same record within 24 hours, but however after 24 hours the insertion should be enabled can any one help me please.
I am using asp.net and vb.net.
I have the following fields in my sqldatabase and text boxes on my asp.net form
ClientID, firstName, lastName, DoB
PLEASE HELP ME

推荐答案

要防止它们在24小时内多次插入同一条记录,您要做的就是在主键中添加一个整数字段并它是 DateTime.DayOfYear [ ^ ].因此,每天他们只能插入一个记录.我不确定这是否对您在问题中提出的那种桌子有意义,但是您要的就是它.

问候,

Manfred
To keep them from inserting the same record more than once within 24 hours all you need to do is add an integer field to your primary key and make it the DateTime.DayOfYear[^]. So each day they can only insert one record. I''m not sure if this even makes sense for the kind of table you proposed in your question, but you asked for it and here it is.

Regards,

Manfred


您可以在表中添加日期,并在包括今天日期在内的特定字段上指定唯一索引.
You could add a date to the table and specify a unique index on the specific fields including todays date.
CREATE TABLE [dbo].[Clients] (
  client_id int ,
  first_name string NOT NULL,
  last_name string NOT NULL
  created_on date NOT NULL
  CONSTRAINT clients_unique UNIQUE ([first_name], [last_name], [created_on])
) ON [PRIMARY]


这样,就不可能在特定日期添加具有相同名字和姓氏的第二个客户端.

祝您好运!


This way it becomes impossible to add a second client with the same first and last name on a certain date.

Good luck!


您可以将当天添加到列列表中,并使用列集合作为唯一标识符.

这可能不是最好的方法,但这是我想起要在SQL中获取日期的方法:

You could add the current day to the list of columns and use collection of columns as the unique identifier.

This probably isn''t the best way, but this is what I remember off of the top of my head to get the date in SQL:

Select Cast(Floor(Cast(getdate() as float)) as datetime)


这篇关于防止在24小时内重复记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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