Content:
Trigger: insetead of alternative triggers,
After the trigger, can only be defined on the table, not on view
Delete the data before the
Inserted after the operation of the new data
For example:
Create the trigger tr_update
On the userinfo
Insetead of update - instead of trigger
As
The begin
Declare @ name varcgar (50)
Select @ name=Customers from inserted
If (@ name='zhang')
Update the userinfo set customername='king fry'
The else
Update the userinfo set customername='three A'
End
Their understanding of the trigger; Alternative to trigger is between begin and end part, to replace, can also be understood as alternatives to trigger changes won't be successful
After the trigger: after using the trigger, is to execute a statement first, and then to carry out the contents of the trigger, execute the statement must be able to perform a successful
Two temporary table respectively: inserted, delete
The insert - inserted data
- delted countless according to
The delete contrary to insert
Update - inserted the modified data
- delted modify the data before the
Cursor:
Role: to deal with data line by line
Use process: 1. Definition 2. Open 3. Using 4. Close the 5. Release
- 1. The cursor practice
Declare @ price money, @ name varchar (200), @ id int
Declare cur_changeprice cursor
For the select id, name, sellprice from Product where SellPrice<=500
The open cur_changeprice
The fetch next cur_changeprice into @ id, @ name, @ price
While @ @ FETCH_STATUS=0
The begin
If (@ price<100 and CHARINDEX (' jeans' @ name) & gt; 0)
The begin
Update the Product set SellPrice=SellPrice * 1.1 where id=@ id
End
If (@ price>=100 and @ price & lt;=500 and CHARINDEX (' t-shirts, @ name) & gt; 0)
The begin
Update the Product set SellPrice=SellPrice * 1.05 where id=@ id
End
The fetch next from cur_changeprice into @ id, @ name, @ price
End
The above is my understanding of the cursor and the trigger, if any problem, please contact me, I will correct, after all, the first post, also, every brother please advice a lot