MS SQL Server
  Home arrow MS SQL Server arrow Page 4 - Exception Handling in SQL Server 2000 and ...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MS SQL SERVER

Exception Handling in SQL Server 2000 and 2005
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 46
    2006-05-24

    Table of Contents:
  • Exception Handling in SQL Server 2000 and 2005
  • How to create a stored procedure in SQL Server 2000 with exception handling: source code
  • How to create a stored procedure in SQL Server 2000 with exception handling: explanation
  • How to create a stored procedure in SQL Server 2005 with exception handling: source code
  • How to create a stored procedure in SQL Server 2005 with exception handling: explanation

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Exception Handling in SQL Server 2000 and 2005 - How to create a stored procedure in SQL Server 2005 with exception handling: source code


    (Page 4 of 5 )

     
    Create the same two tables in SQL Server 2005 as specified in the first section. Now, let us modify the previous procedure with a better approach in SQL Server 2005.  What follows is the modified code.
     
    DropProcedure dbo.sp_emp_insert
    go
     
    createprocedure [dbo].[sp_emp_insert]
    (
          @empno      int,
          @ename      varchar(20),
          @sal  float,
          @deptno int
    )
    as
    begin
     
    begintry
     
          begin transaction
          insert into emp (empno,ename,sal,deptno)
                values (@empno,@ename,@sal,@deptno)
          commit transaction
     
    endtry
    begincatch
          rollback transaction
          insert into error_log (LogDate,Source,ErrMsg)
                values (getdate(),'sp_emp_insert',error_message())
     
    endcatch
     
    end
     
    The execution is very similar to that of the previous code.  You simply issue and execute the following statement in SQL Server Management Studio:
     
    exec sp_emp_insert 1003,'ccc',4000,30
     
    The execution again is very similar to what we've previously seen. You simply issue and execute the following statement in SQL Server Management Studio.  The explanation for the above code is given in the next section.
     

    MS SQL SERVER ARTICLES

    - Completing the Introduction to Transact-SQL
    - A Brief Introduction to Transact-SQL
    - Lookups and Blocking Bad Data
    - Field Validation Rules for Blocking Bad Data
    - Using Masks to Block Bad Data
    - Blocking Bad Data
    - Using @@ROWCOUNT and TABLE Variables for Dat...
    - How to Use Variables, IF and CASE in Databas...
    - Creating Important Aspects of Notification S...
    - Working wth Variables in Database Interactio...
    - Delving Deeper into Notification Services
    - Notification Services
    - Building a Multi-table Report with SQL 2005 ...
    - A Secure Way of Building Connection Strings
    - Transferring a Database Using the SSIS Desig...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT