SQL Server stored procedures, common formats

Source: Internet
Author: User
Tags rowcount

BEGIN
SET NOCOUNT on;
If @_mode not in (' A ', ' M ', ' D ')
Begin
RAISERROR (' parameter Error! ', 16, 3);
Return
End

declare @rowcount int, @error int;

If @_mode= ' A '
Begin
Insert into Szdxinfo (id,bh,[name],nation) Select
@Id, @Bh, @Name,
@Nation;
If @ @error <>0 return;
End

If @_mode= ' M '
Begin
Update Szdxinfo set [Name][email protected],
[Email protected]
where [email protected];
Select @[email protected] @error, @[email protected] @rowcount;
If @error <>0 return;
If @rowcount <>1
Begin
RAISERROR (' No record changed! ', 16, 3)
Return
End
End

If @_mode= ' D '
Begin
Delete Szdxinfo where [email protected];
  select @[email protected] @error, @[email protected] @rowcount;
If @error <>0 return;
If @rowcount <>1
Begin
RAISERROR (' No record deleted! ', 16, 3)
Return
End
End

INSERT into Actionlog ([Date],[userid],computerid,
Tablename,[action]) Select
GETDATE (), @_userid,
@_computerid,
' Szdxinfo ', @_mode;

/*
exec update_szdxinfo @id = ' 11 ',
@Name = ' Liu xxx ',
@Nation = ' Han ',
@_mode = ' A ',
@_userid=1,
@_computerid=1
SELECT * FROM Szdxinfo
*/
END

SQL Server stored procedures, common formats

Related Article

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.