我在Microsoft SQL Server中有一个表,它当前已设置,以便在添加行时,它会将行添加到列名称Date中。我使用getdate()
作为此列的默认值来完成此操作。问题是放在行中的数据是前一天的数据。如何设置默认值,以便在添加行时,而不是将当前日期添加到日期列,它会添加前一天的日期?
答案 0 :(得分:1)
答案 1 :(得分:0)
<img src="http://placehold.it/1" style="display:inline-block;background-color:#000000; width: 256px; height: 256px; cursor: pointer; border: 5px solid #000000;"
onClick="this.src='https://i.imgur.com/M5VkVbK.png'
this.style.width='266px';this.style.height='266px'
;this.style.cursor='default'"/>
如果您只想添加日期,而不是时间部分,请改用CREATE TABLE #test (
ID INT,
myDate DATETIME CONSTRAINT DF_Date DEFAULT DATEADD(DAY, -1, GETDATE())
);
INSERT INTO #test ( ID ) VALUES ( 1 );
SELECT *
FROM #test
。