Try {} catch {} instance in SQL

Source: Internet
Author: User

 

 

Alter procedure [dbo]. [P_DangerSource_File_Add]
@ SourceName varchar (50), -- name
@ TypeID int, -- type
@ DangerLevel varchar (30), -- hazard level
@ IsControl bit, -- whether to monitor
@ SourceLocation varchar (200) -- hazard source location
@ SourceNum int, -- number of hazard sources
@ Descrip varchar (200) -- hazard description
@ Accident varchar (150), -- an Accident may occur
@ Summarize varchar (200), -- Overview
@ Supervisor varchar (30), -- owner
@ Telephone varchar (50), -- contact number
@ UserID varchar (50), -- registrant ID
@ InDate datetime, -- Registration Date
@ IsChanged bit, -- whether to change
@ DeptID varchar (20) -- department ID
AS

Begin Try

Insert into T_DangerSource_File (
[SourceName],
[TypeID],
[DangerLevel],
[IsControl],
[SourceLocation],
[SourceNum],
[Descrip],
[Accident],
[Summarize],
[Supervisor],
[Telephone],
[UserID],
[InDate],
[IsChanged],
[DeptID]
) VALUES (
@ SourceName,
@ TypeID,
@ DangerLevel,
@ IsControl,
@ SourceLocation,
@ SourceNum,
@ Descrip,
@ Accident,
@ Summarize,
@ Supervisor,
@ Telephone,
@ UserID,
@ InDate,
@ IsChanged,
@ DeptID
)

Return SCOPE_IDENTITY () -- returns the ID last inserted to the data table

End Try

Begin Catch
Return-1
End Catch

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.