我需要確保我的某個列的條目可以稱爲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