SQL server-Stored Procedures

Source: Internet
Author: User

--================================ -- ylb:存储过程创建与操作 --================================ use pubs go --一、无参存储过程 --1,创建存储过程 create procedure PTitles as select * from titles go --2,执行存储过程 execute PTitles go --3,移除存储过程 --drop procedure PTitles go --============================== -- ylb:存储过程-入参 -- 16:44 2011/12/14 --============================== use pubs go --1,创建带入参存储过程 select * from titles where type= ‘business‘ go create proc P_Titles_ByType @type char (12) --入参 as select * from titles where [email protected] go --2,执行带参数的存储过程 --a)方式一 exec P_Titles_ByType @type= ‘business‘ go --b)方式二 exec P_Titles_ByType ‘business‘ go --P1:写一个存储过程,要求图书类型是business且单价大于10的所有信息 --P1_1,创建存储过程 select * from titles where type= ‘business‘ and price>10 go create proc P_Titles_ByTypeAndPrice @type char (12), --入参 @price money --入参 as select * from titles where [email protected] and price>@price go --P1_2,执行存储过程 exec P_Titles_ByTypeAndPrice @type= ‘business‘ ,@price=10 go exec P_Titles_ByTypeAndPrice @price=10,@type= ‘business‘ go exec P_Titles_ByTypeAndPrice ‘business‘ ,10 go --是错的,当你直接给值时,一定注意参数的顺序和类型。 --exec P_Titles_ByTypeAndPrice 10,‘business‘ --================================ -- ylb:存储过程-带入参和出参 -- 16:44 2011/12/14 --================================ use pubs go select * from titles --P1:查图书编号是“BU1032”的图书的单价是多少? select price from titles where title_id= ‘BU1032‘ go --P1_1,创建 create proc P_Titles_ByTitleID_SelectPrice @title_id varchar (6) --入参 as select price from titles where [email protected]_id go --P1_2,执行 exec P_Titles_ByTitleID_SelectPrice ‘BU1032‘ go --P2_1,创建 create proc P_Titles_ByTitleID_SelectPrice2 @title_id varchar (6), --入参 @price money output --出参【出参加标识(output)】 as select @price=price from titles where [email protected]_id --出参的@在=左边 go --1,先声明变量 declare @price2 money --2,之后在调用 exec P_Titles_ByTitleID_SelectPrice2 @title_id= ‘BU1032‘ , @[email protected] output --3,再之后在查声明变量 select @price2 --出参要声明,配参后面要加output标识,之后再查声明变量。

SQL server-Stored Procedures

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.