Managing a Transaction Inside a Stored Procedure : Procedure « Procedure Function « SQL Server / T-SQL Tutorial

SQL Server / T-SQL Tutorial
1. Query
2. Insert Delete Update
3. Table
4. Table Join
5. Data Types
6. Set Operations
7. Constraints
8. Subquery
9. Aggregate Functions
10. Date Functions
11. Math Functions
12. String Functions
13. Data Convert Functions
14. Analytical Functions
15. Sequence Indentity
16. View
17. Index
18. Cursor
19. Database
20. Transact SQL
21. Procedure Function
22. Trigger
23. Transaction
24. XML
25. System Functions
26. System Settings
27. System Tables Views
28. User Role
29. CLR
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
SQL Server / T-SQL Tutorial » Procedure Function » Procedure 
21. 8. 9. Managing a Transaction Inside a Stored Procedure
11CREATE PROC usp_MyProc
12> AS
13> DECLARE
14>   @TranCount  int
15> SET
16>   @TranCount = @@TRANCOUNT
17> IF @TranCount > 0
18>   SAVE TRAN usp_MyProc             -- No existing transaction
19> ELSE
20>   BEGIN TRAN usp_MyProc            -- Transaction in progress
21> --do work here ...
22> IF @@ERROR > 0
23BEGIN                              -- Failure
24>   RAISERROR ('usp_MyProc - Bailing out. ', 161)
25>   ROLLBACK TRAN usp_MyProc
26>   RETURN
27END
28> ELSE IF @Trancount = 0             -- Started our own transaction
29>   COMMIT TRAN usp_MyProc           -- Success
30> GO
1>
2> drop procedure usp_MyProc
3> GO
21. 8. Procedure
21. 8. 1. calls the procedure
21. 8. 2. Declare a variable in a procedure
21. 8. 3. Stored Procedures as Parameterized Views
21. 8. 4. PRINT information out of a PROCEDURE
21. 8. 5. Procedure as a view
21. 8. 6. Return a value out of a procedure
21. 8. 7. Returning Values from a View as Stored Procedure Output Parameters
21. 8. 8. Filtering for Null Values with a Stored Procedure
21. 8. 9. Managing a Transaction Inside a Stored Procedure
21. 8. 10. Encrypting a Stored Procedure
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.