Vad*_*dim 1 sql sql-server null
我EntryDate在SQL Server数据库中有一列.
如果查询中未提供值,如何设置NULL值以填充今天的日期(服务器时间)?
Mar*_*ith 11
禁止列上的Null并在列上设置默认值 getdate()
/*Deal with any existing NULLs*/
UPDATE YourTable SET EntryDate=GETDATE() WHERE EntryDate IS NULL
/*Disallow NULLs*/
ALTER TABLE YourTable ALTER COLUMN EntryDate DATE NOT NULL
/*Add default constraint*/
ALTER TABLE YourTable ADD CONSTRAINT
DF_YourTable_EntryDate DEFAULT GETDATE() FOR EntryDate
Run Code Online (Sandbox Code Playgroud)