Copy a column from a table to another table in SQL Server 2008 R2
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
.
精彩评论