If I have a primary key in table A and in table B of the same database (table B has its own primary key) I create a relationship with the primary key in table A so that a column in table B is the foreign key, does it mean that the primary key data created in the primary key column of table A will also be added to table B by virtue of it being a foreign key column or do I have to code that relationship, and if so how do I go about that?
Share
In response to your question:
You will need to define the relationships between the two tables. Example:
When you insert a record into tableB you will still need to define tableAId is. SQL Server doesn’t magically know what this should be.
So hypothetically if tableA looked like this:
To insert a record in tableB that referenced record 2 you would need to do this:
This assumes tableB has the following structure: