美文网首页
SQL server存储过程实例

SQL server存储过程实例

作者: 42c64edf12e9 | 来源:发表于2019-07-26 23:29 被阅读0次

--有输入参数的存储过程--
create proc GetComment
(@commentid int)
as
select * from Comment where CommentID=@commentid

--有输入与输出参数的存储过程--
create proc GetCommentCount
@newsid int,
@count int output
as
select @count=count(*) from Comment where NewsID=@newsid

--返回单个值的函数--
create function MyFunction
(@newsid int)
returns int
as
begin
declare @count int
select @count=count(*) from Comment where NewsID=@newsid
return @count
end

--调用方法--
declare @count int
exec @count=MyFunction 2
print @count

--返回值为表的函数--
Create function GetFunctionTable
(@newsid int)
returns table
as
return
(select * from Comment where NewsID=@newsid)

--返回值为表的函数的调用--
select * from GetFunctionTable(2)

相关文章

  • SQL server存储过程实例

    --有输入参数的存储过程--create proc GetComment(@commentid int)assel...

  • SQL Server存储过程实例

    1、不带参数的存储过程 2、带参数的存储过程 3、参数带默认值的存储过程 4、创建带输出参数的存储过程 5、存储过...

  • SQL Server OFFSET 分页存储过程

    SQL Server OFFSET 分页存储过程 普通sql

  • SQL SERVER 单游标存储过程

    SQL SERVER 单游标存储过程模板

  • SQL Server 存储过程简介与实例

    Transact-SQL中的存储过程,非常类似于Java语言中的方法,它可以重复调用。当存储过程执行一次后,可以将...

  • SQL之存储过程

    SQL Server 存储过程 存储过程(Stored Procedure)是一组为了完成特定功能的SQL 语句集...

  • SQL Server存储过程总结

    SQL Server存储过程总结 存储过程简介: 存储过程(Stored Procedure)是在大型数据库中,一...

  • SQL SERVER存储过程

    什么是存储过程 存储过程就是能完成一定操作的一组SQL语句。这里说的SQL语句是指ANSI SQL的扩展集T-SQ...

  • Sql Server 存储过程

    存储过程 一组预编译的SQL语句,包含数据操作语句,逻辑控制语句和调用函数等 优点 执行速度快 允许模块化程序设计...

  • SQL Server存储过程

    存储过程(stored procedure)是一组为了完成特定功能的SQL语句集合,经编译后存储在服务器端的数据库...

网友评论

      本文标题:SQL server存储过程实例

      本文链接:https://www.haomeiwen.com/subject/kcgjrctx.html