存储过程中的多个命令 [英] multiple command in stroed procedure

查看:72
本文介绍了存储过程中的多个命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在登录表上使用select,insert,update,delete和多个命令来创建存储过程
登录表是

I want to create stored procedure with multiple command as select ,insert,update,delete on login table
login table is

create table Login
(
Emp_name varchar(20),
id varchar(10),
password varchar(10),
Address varchar(20)
);


请帮我怎么做?


Please help me how?

推荐答案

create proc proc_name  para_command varchar
as
begin
if para_command="select"
begin
--select operation
end
if para_command="inser"
begin
--inser operation
end
if para_command="update"
begin
--updateoperation
end
if para_command="delete"
begin
--delete operation
end
end



希望这能解决您的问题



hope this will solve ur problem




试试这个
Hi,

try this
create procedure usp_LoginTable
(
	@intOption int=0 ,/* 1 for insert, 2 for update, 3 for delete*/
	@Emp_name varchar(20)='',
	@id varchar(10)='',
	@password varchar(10)='',
	@Address varchar(20)=''
)
as
begin
IF @intOption=1 --INSERT
	begin	
		insert into [Login](Emp_name,id,[password],[Address])
		values (@Emp_name,@id,@password,@Address)
	end
ELSE IF @intOption=2	---UPDATE
	begin
		update [Login] set Emp_name=@Emp_name,id=@id,[password]=@password,[Address]=@Address
		where 	id=@id
	end
ELSE IF @intOption=3	---DELETE
	begin
		Delete from [Login] where 	id=@id
	end
end


祝你好运
快乐编码:)


Best Luck
Happy Coding:)


这篇关于存储过程中的多个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆