Home > Database > Mysql Tutorial > 使用 SQL Server 添加删除修改查询储存过程

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

WBOY
Release: 2016-06-07 16:21:54
Original
1382 people have browsed it

--添加 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_execute

   --添加

  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

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template