存儲過程if (object_id('proc_find_stu', 'P') is not null) drop proc proc_find_stugocreate proc proc_find_stu(@startId int, @endId int,@outID int output)as ...
存儲過程
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
觸發器---修改觸發器
create trigger class_stu
on goods
for update
as
declare @oldnumber int,@newnumber int,@id int ;
select @oldnumber= number from deleted;--舊數量
select @id= goodsid from deleted ;--id
select @newnumber = number from inserted;--新數量
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
視圖
use Students
select * from Studentss
--創建視圖
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
--修改視圖
alter view v_stu as select id, name, sex from student;
alter view v_stu(編號, 名稱,班級, 小組名稱,筆試,機試) as select Id, StuName, StuClass, TeamName,Bishi,Jineng from Studentss
select * from v_stu where 班級='1510A';
select * from information_schema.views;