开发者

Copy a column from a table to another table in SQL Server 2008 R2

开发者 https://www.devze.com 2023-04-04 00:18 出处:网络
All of my tables have a GateCode column which is used for replication purposes. I have a table 开发者_JAVA百科Configuration which has a GateCode column and all tables primary keys are composite of Ga

All of my tables have a GateCode column which is used for replication purposes.

I have a table 开发者_JAVA百科Configuration which has a GateCode column and all tables primary keys are composite of GateCode foreign key and an ID which is identical.

My problem is I want to not fill GateCode in each table in insertion so this field in each table be filled automatically from Configuration table.

What should I do?

I use SQL Server 2008 R2


If I understand correctly, you want to fill the GateCode column for each table in your database with a value that's stored in your Configuration table, when any new row is inserted into any of the tables - right?

The only way I see to do this is to have INSTEAD OF INSERT triggers on each table. In that trigger, you would then read out the value from the Configuration table, and fill the GateCode column the newly inserted rows so that when the actual INSERT happens, the value is there and the composite primary key will be filled and NOT NULL.

0

精彩评论

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