将SQL Server中的datetime字段的默认值添加到时间戳 [英] Add default value of datetime field in SQL Server to a timestamp

查看:202
本文介绍了将SQL Server中的datetime字段的默认值添加到时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张收集从我们网站提交的表单的表格,但由于某些原因,创建表格时,表格中没有添加时间戳。我想要输入记录的确切日期和时间。



我知道它在某处,但我似乎找不到如何设置默认值(如在Access中,使用getNow()或Now()),但我不知道在哪里放。

解决方案

要修改现有表中的现有列:

  ALTER TABLE YourTable ADD CONSTRAINT DF_YourTable DEFAULT GETDATE()FOR YourColumn 


I've got a table that collects forms submitted from our website, but for some reason, when they created the table, they didn't put a timestamp in the table. I want it to enter the exact date and time that the record was entered.

I know it's in there somewhere, but I can't seem to find how to set the default value (like in Access, you use getNow() or Now()) but I don't know where to put it.

解决方案

For modifying an existing column in an existing table:

ALTER TABLE YourTable ADD CONSTRAINT DF_YourTable DEFAULT GETDATE() FOR YourColumn

这篇关于将SQL Server中的datetime字段的默认值添加到时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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