易截截图软件、单文件、免安装、纯绿色、仅160KB

关于Sql存储过程


SQL 中的存储过程:
1.在建立存储过程之前检查所命名的存储过程是否应经存在。(因为如果同名存储过程已经存在,新的存储过程将不被建立)
if exists(select * from sysobject where name='proc name' and type='p')
drop proc proc name
   go
2.定义存储过程
create proc test
@gradel int, --定义变量
@gradeh int output --定义输出变量
as
...
go
3.执行存储过程
declare @l int,@h int
exec proc test 34,@h output
print @h
----------------------------------------------
下面以一个例子说明:
输入两个分数,要求写两个存储过程,一个对输入分数排序,另一个查询两分数段之间的成绩:
一共有三个表:
s表:(s#:学生号,sname:学生姓名,age:年龄,sex:性别)
c表:(c#:课程号,cname:课程名,teacher:老师)
sc表:(s#,c#,grade)
if exists(select * from sysobjects where name='sort'
          and type='p')
drop proc sort
go --定义一个存储过程用于排序
create proc sort
@high int,
@low int,--定义两个输入参数
@hi int output,
@lo int output--定义两个输出参数
as
if @high<@low
begin
set @high=@high+@low
set @low=@high-@low
set @high=@high-@low
set @hi=@high
set @lo=@low
end
go --如果未按顺序输入则排序
if exists(select * from sysobjects where name='search' and type='p')
drop proc search
go --定义一个存储过程用于查找相应范围的记录
create proc search
@gradeh int,
@gradel int
as
select * from sc where grade between @gradel and @gradeh
if @@rowcount=0
print '查询失败'
go
declare @h int,@l int
exec testpro 70,90,@h output,@l output
exec search @h,@l
参考:http://hi.baidu.com/rosalind1717/blog/item/bcb26ceea5a418212cf534ce.html
http://hi.baidu.com/isbx/blog/item/3e06ae514c35ac878d543094.html


相关文档:

SQL SERVER的审计功能

      启用c2审核命令如下:
      EXEC sp_configure 'c2 audit mode', '1' RECONFIGURE      
      SQL Server以128KB大小的块为单位把数据写入跟踪文件。因此,当SQL Server非正常停止时,最多可能丢失128
......

查询重复记录的SQL语句

SELECT tagid, tagname from uchome_mtag WHERE tagname IN (SELECT tagname from uchome_mtag GROUP BY tagname HAVING (COUNT(tagname) > 1)) ORDER BY tagname ......

三中SQL 分页方法效率分析

三种SQL分页法效率分析
表中主键必须为标识列,[ID] int IDENTITY (1,1)
1.分页方案一:(利用Not In和SELECT TOP分页)
 语句形式:利用Not In和SELECT TOP分页) 效率中,需要拼接SQL语句
  SELECT TOP 10 * from  TestTable WHERE (Id  NOT  IN (SELECT  TOP  20    id&n ......

SQL Server中索引

一、SQL Server中数据行的存储方式
     在SQL Server中存放数据的文件会以8KB的大小分页。每一页可以是数据、索引以及其他SQL Server数据库需要为其维护数据文件的数据类型。大多数页是数据页或索引页。页是SQL Server读、写数据文件的单元。每一页只包括一个对象的数据或索引信息,所以在每一个数据 ......

SQL output使用

SQL版:
alter proc testguo
(
    @cityid int,
    @cityname nvarchar(100) output
)
as
select @cityname =  city_name from BA_Hot_City where cityid = @cityid
select @cityname
go
declare @cityname nvarchar(100)
exec testguo 1,@cityname output
另一版:
ht ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号