if there is any technique to insert values into multiple tables in sql Server 2008 Database?
Posted
by
Krishanu Dey
on Stack Overflow
See other posts from Stack Overflow
or by Krishanu Dey
Published on 2012-04-02T23:20:44Z
Indexed on
2012/04/02
23:29 UTC
Read the original article
Hit count: 218
I just wanted to know, if there is any technique to insert values into multiple tables in sql Server 2008 Database?
I've got the following
cmd.CommandText = "Insert into tb1 (col1, col2, col3) values (@col1, @col2, @col3); Insert into tb2 (col1, col2, col3) values (@col11, @col12, @col13);";
cmd.Parameters.AddWithValue("col1","val1");
cmd.Parameters.AddWithValue("col2", "val2");
cmd.Parameters.AddWithValue("col3", "val3");
cmd.Parameters.AddWithValue("col11","val4"); cmd.Parameters.AddWithValue("col12", "val5");
cmd.Parameters.AddWithValue("col13", "val6");
But will values be inserted to "tb1" even if "Insert into tb2..." part gets an error? if yes then it is not what i wanted. i wanted that, values should not be inserted into tb1 if tb2 part gets an error.
please help me out.
© Stack Overflow or respective owner