SQLSERVER存储过程
创建存储过程
USE [test] GO /****** Object: StoredProcedure [dbo].[table2] Script Date: 11/28/2022 10:38:03 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE proc [dbo].[table2]( @ExeType varchar(50), --执行类型 @a1 varchar(50), --Table_1字段 a1 @sr varchar(50), --Table_1字段 sr @msg varchar(50) out --msg出参信息 ) as begin if(@ExeType='Insert') begin insert into Table_1(a1,sr) values(@a1,@sr); set @msg='插入成功'; end else if(@ExeType='Delete') begin delete from Table_1 where a1=@a1; set @msg='删除成功'; end else if(@ExeType='Update') begin update Table_1 set sr=@sr where a1=@a1; set @msg='修改成功'; end else if(@ExeType='Select') begin select * from Table_1 where a1=@a1; end end GO
执行存储过程
declare @msg varchar(50) exec table2 'Insert','322222','434',@msg output select @msg;