First, paste a self-written stored procedure for adding logs:
Alter procedure [DBO]. [writeblog] (@ in_id varchar (10), @ in_event varchar (100), @ out_parameter varchar (10) Output) as/** log writing stored procedure @ in_id user ID @ in_event Operation Event @ in_datetime operation time @ out_parameter return value 0 operation successful 1 Write failed */declare @ in_datetime datetime; set @ in_datetime = getdate (); begin tryinsert into blog values (@ in_id, @ in_event, @ in_datetime); Set @ out_parameter = '0 '; end trybegin catchset @ out_parameter = @ error; end catchreturn
Note:
The function of a stored procedure is to write its log information based on each operation on the database.
Exception Handling is critical, especially when a function or stored procedure returns a function or process. If you can include exception handling in the return value, in this way, you will know the exceptions when calling this process or function, so that you can debug them step by step.
The Stored Procedure also contains try catch statements, which are written in the above example.
For exception details, refer to the blog:
Http://www.cnblogs.com/sshoub/archive/2011/08/12/2136267.html