• 爱情文章
  • 亲情文章
  • 友情文章
  • 生活随笔
  • 校园文章
  • 经典文章
  • 人生哲理
  • 励志文章
  • 搞笑文章
  • 心情日记
  • 英语文章
  • 范文大全
  • 作文大全
  • 新闻阅读
  • 当前位置: 山茶花美文网 > 范文大全 > 正文

    [使用,SQL,Server,添加删除修改查询储存过程] 储存过程

    时间:2020-05-28来源:山茶花美文网 本文已影响 山茶花美文网手机站

    --添加

    create procedure usp_add

    (

    @table nvarchar(255),

    @values nvarchar(max)=null

    )

    as

    declare @sql nvarchar(max)

    set @sql="insert into "+@table

    if @values is not null

    set @sql="insert into "+@table+" values("+@values+")"

    exec sp_executesql @sql

    select @@IDENTITY

    go

    exec usp_Add "金山股份" ,"""abc"",20,300"

    go

    --删除

    create procedure usp_delete

    (

    @table nvarchar(255),

    @where nvarchar(max)=null

    )

    as

    declare @sql nvarchar(max)

    set @sql="delete "+@table

    if @where is not null

    set @sql+=" where "+@where

    exec sp_executesql @sql

    go

    exec usp_delete "金山股分","id=1"

    go

    --修改

    create procedure usp_update

    (

    @table nvarchar(255),

    @set nvarchar(max),

    @where nvarchar(max)=null

    )

    as

    declare @sql nvarchar(max)

    set @sql="update "+@table+" set "+@set

    if @where is not null

    set @sql+=" where "+@where

    exec sp_executesql @sql

    go

    exec usp_update "金山股份","StockName=""腾讯股分""","id=2"

    go

    --查找

    create procedure usp_select

    (

    @table nvarchar(255),

    @where nvarchar(max)=null

    )

    as

    declare @sql nvarchar(max)

    set @sql="select * from "+@table

    if @where is not null

    set @sql=@sql+" where "+@where

    exec sp_executesql @sql

    go

    exec usp_select "Stock","id=1"

    go

    • [使用,SQL,Server,添加删除修改查询储存过程] 储存过程 相关文章:
    • 爱情文章
    • 亲情文章
    • 友情文章
    • 随笔
    • 哲理
    • 励志
    • 范文大全