插入日期的默认 getdate [英] Default getdate for Insert date

查看:25
本文介绍了插入日期的默认 getdate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 sample 的表,它有一个名为 [__INSERT_DATE] 的列,该列为空.现在我想更改默认为 getdate() 的列.当我尝试以下操作时,它给了我一个错误.

I have a table called sample and it has a column called [__INSERT_DATE] which is null. Now I want to alter the column with default as getdate(). When I tried the following it gave me an error.

ALTER TABLE sample
ALTER COLUMN [__INSERT_DATE] [datetime] DEFAULT (getdate()) NULL)

谁能告诉我这是什么问题?

Can anyone tell me what the problem is?

推荐答案

试试这个:

ALTER TABLE MyTable ADD CONSTRAINT
DF_MyTable_Inserted DEFAULT GETDATE() FOR INSERT_DATE
GO

假设您的表名为MyTable,列为INSERT_DATE,并且约束的名称为DF_MyTable_Inserted

This assumes your table is named MyTable, the column is INSERT_DATE, and the name of the contstraint is to be DF_MyTable_Inserted

这篇关于插入日期的默认 getdate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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