In fact, it's easy. SQL Server stored procedures and triggers

Source: Internet
Author: User

1. Declaration and use of variables

DECLARE @var as varchar (50)

Set var= ' ABCD '

2. If loop

If IsNull (@prjid, 0) =0
Begin
print ' did not find prjid!!! ‘
Return
End
Else

Begin

--You must write some code here, otherwise you will get an error.

End

3, the use of cursors

    1. DECLARE CURJD cursor for
    2. Select Id,fzbh from _tzk
    3. Open CURJD
    4. FETCH NEXT from CURJD to @jdID, @paperno
    5. While @ @FETCH_STATUS =0
    6. BEGIN
    7. --Here are some handling code
    8. FETCH NEXT from CURJD to @jdID, @paperno
    9. END
    10. Close CURJD
    11. Deallocate CURJD

4, the use of triggers

The key is the use of inserted tables and deleted tables

  1. ALTER TRIGGER Roleinsert on [dbo]. [RoleName]
  2. After INSERT
  3. As
  4. Declare @RoleID as bigint
  5. Set @RoleID = (select Roleid from inserted)
  6. Insert into Rolerule (ROLEID,MENUID,PW)
  7. Select @roleid, MenuID,0 from menus where menus. MenuID
  8. (select MenuID from Rolerule where Role[email protected])
  9. Update Rolerule set pw=1 where MenuID in (select MenuID from menus where always=1)
  10. and Roleid in (select Roleid from inserted)

And then with these few examples, the other is a process of proficiency.

In fact, it's easy. SQL Server stored procedures and triggers

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.