存儲過程(stored procedure)類似c語言中的函數(shù)器罐,是一組為了完成特定功能的SQL語句集,經(jīng)編譯后存儲在數(shù)據(jù)庫中渐行。用戶通過指定存儲過程的名字餅給出參數(shù)來執(zhí)行它。
常用的系統(tǒng)存儲過程:sp_database,sp_helpdb,sp_renamedb,sp_tables,sp_column,sp_help,sp_helpconstraint,sp_helpindex,sp_stored_procedure,sp_password
創(chuàng)建存儲過程:
create procedure book_num (@book_name varchar(26),@starttime datetime,@endtime datetime,@total int output)
as
select @total=count(jy.askbookid) from book,jyls jy where bookname like @book_name and book.isbn=jy.isbn and jy.starttime>=@starttime and endtime<=@endtime
使用存儲過程:
declare @book_name char(26),@total int
set @book_name='面向?qū)ο蠓治龊驮O(shè)計'
exec book_num @book_name,'2007-01-01','2007-11-01',@total output
select @book_name as bookname,@total as num