SQL數(shù)據(jù)庫(kù)中()函數(shù)作用是獲取系統(tǒng)當(dāng)前時(shí)間。
例如
SELECT GETDATA() AS DataTime --可以查看現(xiàn)在的時(shí)間
工作中用到的sql語(yǔ)句
ALTER TABLE [dbo].[cdc_test_str] ADD CONSTRAINT [DF_cdc_test_str_operation_time] DEFAULT (getdate()) FOR [operation_time]
--添加默認(rèn)值約束
alter table 表名 add 約束名 約束值 for 列名;
ALTER TABLE [dbo].[] ADD [] (()) FOR []
使用T-SQL腳本修改約束
use 數(shù)據(jù)庫(kù)名; --使用數(shù)據(jù)庫(kù)
go
if ( * from where name=約束名) --判斷要?jiǎng)?chuàng)建的約束是否已存在
alter table 表名 drop 約束名;
go
alter table 表名 add 約束名 約束值 for 列名; --添加默認(rèn)值約束
go
示例:
--使用數(shù)據(jù)庫(kù)
use ;
go
--判斷要?jiǎng)?chuàng)建的約束是否已存在
if ( * from where name='')
alter table test1 drop ;
go
--添加默認(rèn)值約束
alter table test1 add 18 for age;
go