SSIS 插入不插入计算列
我正在使用 SSIS 将 Excel 文件插入到 Sql Server 表中。我相信它使用批量插入,因此它不会插入到“CreationDate”和“ModificationDate”列(这两个列都是以 getdate() 作为默认值的计算列)。
有办法解决这个问题吗?
另外,需要明确的是 - 这两个日期列都不属于 Excel 的一部分。这是确切的场景:
我的 Excel 有两列 - 代码和描述。我的 SQL Server 表有 4 列代码、描述、创建日期、修改日期。
因此,当 SSIS 复制数据时,它会复制代码和描述,但 CreationDate 和 ModificationDate(它们是 SQL Server 计算列)都是空的。
I am using SSIS to insert a Excel file into a Sql Server Table. I believe it uses the Bulk insert, and as a result it doesn't insert into the 'CreationDate' and the 'ModificationDate' columns (both of which are computed columns with getdate() as the default).
Is there a way to get around this problem?
Also, just to be clear - both these date columns are not a part of excel. Here is the exact scenario:
My excel has two columns - code and description. My SQL Server table has 4 columns Code, Description, CreationDate, ModificationDate.
So, when the SSIS copies the data, it copies Code and Description, but the CreationDate and ModificationDate (which are SQL Server Computed Columns) are both empty.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您想记录创建,您应该使用带有默认约束的普通列
计算列定义为
每次查询时,GETDATE()
都会改变。计算列也不可能被填充
因此,假设您的意思是“默认的普通列”,那么您需要停止从 SSIS 发送 NULL ,这将覆盖默认值
这一切都在这里演示:
假设您正在使用 SSIS 中的批量插入任务,则需要设置“Keep nulls = off/选项页面中未选中”
You should use a normal column with a default constraint if you want to log creation
A computed column defined as
GETDATE()
will change every time you query it.It is also impossible for a computed column to not be populated
So, assuming you mean "normal column with default", then you need stop sending NULL from SSIS which overrides the default
This is all demonstrated here:
Assuming you are using the Bulk Insert Task in SSIS, then you need to set "Keep nulls = off/unchecked" in the options page
您应该对指定 get 的列有一个默认约束。
还应该有一个用于批量插入
KEEPNULLS
的选项,该选项应该关闭。来自MSDN 上的批量插入:
KEEPNULLS 也有记录: http://msdn.microsoft.com/en-us/库/ms187887.aspx
You should have a default constraint on the column(s) that specifies get
There should also be an option for the bulk insert
KEEPNULLS
which should be turned off.From Bulk Insert on MSDN:
KEEPNULLS is also documented: http://msdn.microsoft.com/en-us/library/ms187887.aspx
将派生列放入数据流中,并使用所需的值填充两个缺失的列。
Put in a Derived Column in your dataflow and populate the two missing columns with the values you want.
计算列上的值实际上并不存在于数据库中,每次 SQL Server 需要访问它时都会计算它,这就是为什么您无法在插入时向其通知值。
您需要的是一个默认列,该列具有默认值,如果您不告知任何其他值,则会插入该默认值。
The value on a computed column doesn't physically exists on the database, it is calculated every time SQL Server needs to access it, that's why you can't inform a value to it on a insert.
What you need is a default column, which is a column that has a default value that's inserted if you don't inform any other value.