All of my tables have a GateCode column which is used for replication purposes.
I have a table 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
GateCodecolumn for each table in your database with a value that’s stored in yourConfigurationtable, 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 INSERTtriggers on each table. In that trigger, you would then read out the value from theConfigurationtable, and fill theGateCodecolumn the newly inserted rows so that when the actualINSERThappens, the value is there and the composite primary key will be filled andNOT NULL.