开发者

MS SQL Server Import - Importing Data With New NON NULL Column

开发者 https://www.devze.com 2023-03-25 15:41 出处:网络
I am trying to imp开发者_JAVA技巧ort from an old database into an updated one. The databases are basically identical except in one of my tables I added a new column that is NOT NULL.

I am trying to imp开发者_JAVA技巧ort from an old database into an updated one.

The databases are basically identical except in one of my tables I added a new column that is NOT NULL.

This obviously makes errors when I used the importer to move the rows over. Is there a way that I can define a default for this new NOT NULL field when doing an Import?


Yes you can add a default constraint to the new column. See this post: Alter column, add default constraint

alter table TableName
add constraint df_ConstraintNAme
default > getutcdate() for [Date]


Two options are:

1) Define a DEFAULT value constraint on the column

2) Temporarily make the column NULL, do the import, then reapply the NOT NULL constraint

0

精彩评论

暂无评论...
验证码 换一张
取 消