--Add
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 ' Jinshan shares ', ' abc ', 20,300 '
Go
--Delete
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 ' Jinshan shares ', ' id=1 '
Go
--Modify
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 ' Jinshan shares ', ' stockname= ' ' Tencent shares ', ' id=2 '
Go
--Find
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