My c# code calls a stored procedure and passes a tvp as an argument to the storerd procedure. I need to insert the received data into several database tables.
TVP schema:
TVP_ID int PRIMARY KEY IDENTITY, Col1 int, Col2 int, Col3 int.
First, I need to insert Col1 to Table1:
Table1 schema:
Table1_ID int PRIMARY KEY IDENTITY, Col1 int
Than, I need to insert all columns into Table2.
Table2 schema:
TVP_ID int, Col1 int, Col2 int, Col3 int, Table1_ID int
where TVP_ID and Table1_ID are primary keys of TVP and Table1 tables.
How can I do that?
Thanks!
Edit: My problem is that when I have Table1 (after data was inserted to col1) the connection between TVP and Table1 is no longer exists. Key of TVP is TVP_ID, key of Table1 is Table1_ID, and I lost the connection between them.
I insert multiple rows, so once I have added multiple rows to Table1 how can I insert multiple rows to table2?
INSERT INTO table (name) VALUES('vivek'); SELECT SCOPE_IDENTITY()get this id and insert into second table - vivek nuna