Stored Procedure, trigger, etc...., stored procedure trigger ..

Source: Internet
Author: User

Stored Procedure, trigger, etc...., stored procedure trigger ..

Stored Procedure

If (object_id ('proc _ find_stu ', 'P') is not null)
Drop proc proc_find_stu
Go

Create proc proc_find_stu (@ startId int, @ endId int, @ outID int output)
As

Select * from Studentss where id between @ startId and @ endId

Set @ outID = (select COUNT (1) from Studentss where id between @ startId and @ endId)



Declare @ ss int = 0;
Exec proc_find_stu 1,6, @ ss out
Select @ ss

Trigger --- modify trigger

Create trigger class_stu
On goods
For update
As
Declare @ oldnumber int, @ newnumber int, @ id int;

Select @ oldnumber = number from deleted; -- old quantity
Select @ id = goodsid from deleted; -- id

Select @ newnumber = number from inserted; -- new quantity

Update cangku set number = @ oldnumber-(@ oldnumber-@ newnumber) where goodsid = @ id;

Drop trigger class_stu

Update goods set number = number-1 where goodsid = 1;

Select * from goods g inner join cangku c on g. goodsid = c. goodsid

View

Use Students
Select * from Studentss
-- Create a view
If (exists (select * from sys. objects where name = 'v _ stu '))
Drop view v_stu

Create view v_stu as select Id, StuName, StuClass, TeamName, Bishi, Jineng from Studentss;

Select * from v_stu


-- Modify View
Alter view v_stu as select id, name, sex from student;
Alter view v_stu (No., name, class, group name, test, and test) as select Id, StuName, StuClass, TeamName, Bishi, Jineng from Studentss

Select * from v_stu where class = '1510a ';

Select * from information_schema.views;

 

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.