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
- DECLARE CURJD cursor for
- Select Id,fzbh from _tzk
- Open CURJD
- FETCH NEXT from CURJD to @jdID, @paperno
- While @ @FETCH_STATUS =0
- BEGIN
- --Here are some handling code
- FETCH NEXT from CURJD to @jdID, @paperno
- END
- Close CURJD
- Deallocate CURJD
4, the use of triggers
The key is the use of inserted tables and deleted tables
- ALTER TRIGGER Roleinsert on [dbo]. [RoleName]
- After INSERT
- As
- Declare @RoleID as bigint
- Set @RoleID = (select Roleid from inserted)
- Insert into Rolerule (ROLEID,MENUID,PW)
- Select @roleid, MenuID,0 from menus where menus. MenuID
- (select MenuID from Rolerule where Role[email protected])
- Update Rolerule set pw=1 where MenuID in (select MenuID from menus where always=1)
- 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