[dba-SQLServer] What happens when

John W. Colby jwcolby at colbyconsulting.com
Sat Jul 24 10:43:11 CDT 2004


What happens in SQL Server when a specific statement fails?

I am looking at a process of building a table, then inserting data into that
table, building another table, placing related data into that table.  All
using SQL.  The statements that place data in the first table require thaqt
the build table statement work of course, and the statements that place data
into the second table should not occur unless the entire first sequence
occurs since the second table is related to the first.

I understand the concept of transactions but what really happens?

Psuedo code

Start transaction
	Build table1
	Insert Row2
	Insert Row3
	Insert Row4

	Build Table2
	Insert row5
	Insert row6
	Insert Row7
Commit 

1) First, can statements that alter the database design be included inside
of transaction statements?  Whould I need to rearrange that to:

	Build table1
	Build Table2

Start transaction
	Insert Row2
	Insert Row3
	Insert Row4

	Insert row5
	Insert row6
	Insert Row7
Commit 
2) Suppose that Build Table1 fails?  Do the rest of the statements attempt
to execute?  Does the process fail immediately and report an error, refusing
to execute any subsequent statements?

3) Suppose that Insert Row3 fails?  Do the rest of the statements attempt to
execute or does the process fail and rollback automatically?

4) Is my process that is executng the code responsible for checking for
errors after each statement?

5) I have discovered how to create a script for creating the table
structure, but how do I create a script for creating the data in the table,
given a table with data in it?

6) Can scripts be executed directly (from windows explorer)?  I can take a
script and paste it into enterprise manager (query analyzer) and execute all
statements at one time.

John W. Colby





More information about the dba-SQLServer mailing list