How can I insert values into two tables at once? if it not successful, both table should rollback.
I am using SQL server and the query passe throw C# code.
You could either run the two queries as one statement
insert into table1 (...) values (...); insert into table2 (...) values (...)
or write a trigger to do the second INSERT.
I would typically write a stored procedure to take in all of the values you want to write out, then call a series of INSERT INTO
statements wrapped in a transaction.
If you provide more information, such as table structure and sample data, we can help you further.
get ans here of ur question
SQL Server: Is it possible to insert into two tables at the same time?
How can I INSERT data into two tables simultaneously in SQL Server?