默认更新约束 [英] Default update contraint
本文介绍了默认更新约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以帮助我,因为我得到的任务如下:
假设我正在进行包含列和数据的表格测试:
Hi,
Could some one please help me as i got a task which is as follows:
Suppose i am having a table test with columns and data :
ID Name Address Create_date Update_date
1 abc india 2013-08-11 NULL
2 xyz india 2013-08-11 NULL
现在,如果您在上面的数据中看到update_date为NULL。现在我希望如果我们在那时更新记录,它应该给我update_date。对于这种方法我不想使用任何触发器。
例如:
如果我更新了行对于Id = 1,那么数据应该是这样的..
Now if you see in the above data the update_date is NULL . Now I want that if we update the record at that time it should give me the update_date. For this approach i dnt want to use any Trigger.
For example:
If i updated row for Id=1 then the data should be like this..
ID Name Address Create_date Update_date
1 abc US 2013-08-11 2013-08-22
谢谢,
Preetpal Kapoor
Thanks,
Preetpal Kapoor
推荐答案
您好,您可以使用GETDATE()
函数。 />
例如
Hi, You could useGETDATE()
function.
E.g.
UPDATE Table_Name
SET Update_Date = CONVERT(char(10), GETDATE(),126)
WHERE ID = 1
默认约束仅适用于插入,更新使用触发器
如果您不想使用triggger,我认为解决此问题并非不可能。
A defaul constraint only works on inserts, for an update use a trigger
If you don't want to use triggger i think that is not impossible to solve this issue.
这篇关于默认更新约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文