我需要确保我的某个列的条目可以称为CreationDate
is = <当前日期。使列值小于或等于当前日期
没有试图利用这个
CHECK (CreationDate =< GETDATE())
对于这篇文章提到的原因后:我想知道 CHECK constraint on date of birth?
我将如何编写SQL Server中的触发器,将检查日期我尝试插入/更新= <的currentdate
我从来没有使用过的触发器,我想出了这一点,但我不知道是否行得通,不然怎么会被调用。 我试图让触发器返回一个错误,以便程序员被迫检查或修复这个问题。
CREATE TRIGGER CheckValidDateTrigger
ON Reports
INSTEAD OF
UPDATE
AS
DECLARE @ReportCloseDate DateTime;
IF (@ReportCloseDate > GETDATE())
BEGIN
RAISERROR ('Error, the date your trying to save cannot be higher or newer that the current date. The date must be in the past or be the current date', -- Message text.
16, -- Severity.
1 -- State.
);
END;
你们能帮我一下吗?
[此问题](http://stackoverflow.com/questions/15803002/date-cannot-be-in-the-future-sql)在最后一个答案中有一个类似的触发器样本。 – Alexander 2013-04-25 20:27:30
您是否试过'CHECK(CreationDate
2013-04-25 20:28:07
应该先测试一下,然后再问是否有效对不起 – Termiux 2013-04-25 20:40:00