can we insert into two tables with single sql statement? can we insert into two tables with single sql statement? sql sql

can we insert into two tables with single sql statement?


No you cannot perform multiple inserts into two tables in one query.


No you can't.

If you want to ensure the atomicity of an operation that requires data to be inserted into 2 tables, you should protect it in a transaction. You either use the SQL statements BEGIN TRAN and COMMIT TRAN, or you use a transaction boundary in whatever language you're using to develop the db access layer. E.g. something like Connection.StartTransaction and Connection.Commit (or Connection.Rollback on an error).


You can call a stored procedure with inserts into two tables.