存储过程几种写法
2007-09-18 16:26
495 查看
1)创建使用参数的存储过程
Create Proc au_info @lastname varchar(40),@firstname varchar(20)
As
Select au_lname,au_fname,title,pub_name
From ...
where au_fname=@firstname And au_lname=@lastname
Go
EXECUTE au_info ringer,anne
2)创建使用参数默认值的存储过程,该存储过程在没有输入参数的情况下将默认值得到的结果输出
Create Proc au_info @lastname varchar(40)='ringer',@firstname varchar(20)='anne'
As
Select au_lname,au_fname,title,pub_name
From ...
where au_fname=@firstname And au_lname=@lastname
Go
EXECUTE au_info
3)用显式值替代参数默认值的存储过程
Create Proc showind @table varchar(30) ='titles'
as
SELECT Table_Name=sysobjects.name,
INDEX_Name=sysindexes.name,index_id=indid
from sysindexes inner join sysobjects on sysobjects.id=sysindexes.id
where sysobjects.name=@table
EXECUTE showind authors
4)使用参数默认值NULL来创建存储过程,在这种情况下如果没有提供参数值,SQL将不会出错显示
Create Proc showind @table varchar(30) =Null
as
IF @table is NUll
print '请输入参数'
else
SELECT Table_Name=sysobjects.name,
INDEX_Name=sysindexes.name,index_id=indid
from sysindexs inner join sysobjects on sysobjects.id=sysindexes.id
where sysobjects.name=@table
EXECUTE showind authors
5)使用包含通配符的参数默认值创建存储过程
通配符包括(% , _ , [ ]和 [^]),注意需要用Like关键字
CREATE PROC au_info @lastname varchar(40)='r%' , @firstname varchar(20)='%' AS
Select au_lname,au_fname,title,pub_name
from authors inner join titleauthor on authors.au_id=titleauthor.au_id
join titles on titleauthor.title_id=titles.title_id
join publishers on titles.pub_id=publishers.pub_id
where au_fname like @firstname
and au_lname like @lastname
GO
Create Proc au_info @lastname varchar(40),@firstname varchar(20)
As
Select au_lname,au_fname,title,pub_name
From ...
where au_fname=@firstname And au_lname=@lastname
Go
EXECUTE au_info ringer,anne
2)创建使用参数默认值的存储过程,该存储过程在没有输入参数的情况下将默认值得到的结果输出
Create Proc au_info @lastname varchar(40)='ringer',@firstname varchar(20)='anne'
As
Select au_lname,au_fname,title,pub_name
From ...
where au_fname=@firstname And au_lname=@lastname
Go
EXECUTE au_info
3)用显式值替代参数默认值的存储过程
Create Proc showind @table varchar(30) ='titles'
as
SELECT Table_Name=sysobjects.name,
INDEX_Name=sysindexes.name,index_id=indid
from sysindexes inner join sysobjects on sysobjects.id=sysindexes.id
where sysobjects.name=@table
EXECUTE showind authors
4)使用参数默认值NULL来创建存储过程,在这种情况下如果没有提供参数值,SQL将不会出错显示
Create Proc showind @table varchar(30) =Null
as
IF @table is NUll
print '请输入参数'
else
SELECT Table_Name=sysobjects.name,
INDEX_Name=sysindexes.name,index_id=indid
from sysindexs inner join sysobjects on sysobjects.id=sysindexes.id
where sysobjects.name=@table
EXECUTE showind authors
5)使用包含通配符的参数默认值创建存储过程
通配符包括(% , _ , [ ]和 [^]),注意需要用Like关键字
CREATE PROC au_info @lastname varchar(40)='r%' , @firstname varchar(20)='%' AS
Select au_lname,au_fname,title,pub_name
from authors inner join titleauthor on authors.au_id=titleauthor.au_id
join titles on titleauthor.title_id=titles.title_id
join publishers on titles.pub_id=publishers.pub_id
where au_fname like @firstname
and au_lname like @lastname
GO
相关文章推荐
- 分页存储过程的几种写法
- T-SQL 存储过程中使用事务的几种写法(摘抄)
- SQL Server 存储过程中处理多个查询条件的几种常见写法分析,我们该用那种写法
- 存储过程几种写法
- 存储过程几种写法
- SQL Server 存储过程中处理多个查询条件的几种常见写法分析,我们该用那种写法
- SQL Server 存储过程的几种常见写法分析,我们该用那种写法
- MySQL中关于行转列的存储过程的写法(使用游标)
- DB2 存储过程的异常处理器类型有几种?
- 常用的几种交互表存储过程的实现方法
- 常用的几种交互表存储过程的实现方法
- mysql 存储过程写法
- oracle 存储过程的写法
- [SQL-码农]建立不输入参数的存储过程的写法
- MySQL 的存储过程写法和Cursor的使用
- 常用的几种交互表存储过程的实现方法
- sybase存储过程的写法以及java的调用方法
- ASP调用带参数存储过程的几种方式 (转)
- DB2 中游标的使用以及 存储过程的写法
- MySQL 的存储过程写法和Cursor的使用