問(wèn)題描述
我正在使用 SSIS 包填充表格.
I am populating a table using an SSIS package.
這個(gè)想法是,每當(dāng)包上傳到表時(shí),它都會(huì)使用 getdate()
對(duì)值進(jìn)行時(shí)間戳.
The idea is that whenever the package uploads to the table, it will timestamp the value using getdate()
.
當(dāng)我打開(kāi)它時(shí),我的 DDL 看起來(lái)是這樣的:
My DDL looks like this when I open it up:
CREATE TABLE [REPORTING].[post_ssis_table_1](
[validation_key] [int] IDENTITY(1,1) NOT NULL,
[ssis_ran_date] [datetime] NULL,
[server_name] [varchar](255) NULL,
[data_base] [varchar](255) NULL,
--A bunch of other irrelevant columns
[success_status] [varchar](255) NULL,
[success_criteria] [varchar](255) NULL,
PRIMARY KEY CLUSTERED
(
[validation_key] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [REPORTING].[post_ssis_tbl_1] ADD DEFAULT (getdate()) FOR [ssis_ran_date]
GO
注意:我沒(méi)有輸入alter語(yǔ)句,這就是我打開(kāi)DDL時(shí)的樣子.
Note: I did not type the alter statement, that's literally what it looks like when I open up the DDL.
為什么在我插入行時(shí)沒(méi)有為 [ssis_ran_date] 填充默認(rèn)值?它實(shí)際上只是保持為空.
Why is the default value not populating for [ssis_ran_date] when I insert rows? It literally just stays null.
推薦答案
如果您的 INSERT 語(yǔ)句為具有默認(rèn)值的列指定 NULL,則將插入 NULL.
If your INSERT statement specifies NULL for a column with a default, then NULL will get inserted.
只有在 INSERT 中根本沒(méi)有指定該列時(shí)才會(huì)使用默認(rèn)值.
The default will only be used when that column is not specified in the INSERT at all.
這篇關(guān)于SQL Server 表不使用默認(rèn)值的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!