SQL数据库中getDate()函数作用是获取系统当前时间。
例如
SELECT GETDATA() AS DataTime --可以查看现在的时间
工作中用到的sql语句
ALTER TABLE [dbo].[cdc_test_str] ADD CONSTRAINT [DF_cdc_test_str_operation_time] DEFAULT (getdate()) FOR [operation_time]
--添加默认值约束
alter table 表名 add constraint 约束名 default 约束值 for 列名;
ALTER TABLE [dbo].[cdc_test_str] ADD CONSTRAINT [DF_cdc_test_str_operation_time] DEFAULT (getdate()) FOR [operation_time]
使用T-SQL脚本修改DEFAULT约束
use 数据库名; --使用数据库
go
if exists(select * from sysobjects where name=约束名) --判断要创建的约束是否已存在
alter table 表名 drop constraint 约束名;
go
alter table 表名 add constraint 约束名 default 约束值 for 列名; --添加默认值约束
go
示例:
--使用数据库
use testss;
go
--判断要创建的约束是否已存在
if exists(select * from sysobjects where name='default1')
alter table test1 drop constraint default1;
go
--添加默认值约束
alter table test1 add constraint default2 default 18 for age;
go