how to add autofill foreign key values in C# sql
Loading
how to add autofill foreign key values in C# sql
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sachin SinghPosted Sep 18, 2022, 7:49 AM
Foreign key (Let's say for Table_A) means primary key of another table (Let's say Table_B). So if Table_B has multiple rows then it will have multiple PK values, So, Table_A FK column should have only those values which are present in Table_B primary key column.
So, when you insert a row in Table_B you can fetch the last PK value using Scope_Identity() and can insert it into FK column in Table_A.
But, i will suggest you to use Stored procedure instead.