在存储过程中运行多个查询语句 [英] Running multiple query statements in Stored Procedure

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

问题描述

嗨朋友,,,,



我想在单个存储过程中运行多个查询语句(INSERT,UPDATE,DELETE)。



但删除查询无效。



任何建议......

Hi Friends,,,,

I want to run multiple query statements(INSERT,UPDATE,DELETE) in a Single Stored Procedure.

But the Delete query is not working.

Any suggestions...

推荐答案

如果你想要单个sp用于crud operaton那么你应该定义@Task变量并使用如果下面的条件将值传递给sp以及其他参数的任务...

if you want single sp for crud operaton then
you should define @Task variable and use if conditions like below pass value to sp for task also with other parameters...
if @Task = 1 
Begin
//insert
return
end 
elseif @Task = 2 
Begin
//update
return
end
elseif @Task = 3
Begin
//Delete
return
end



快乐编码!

:)


Happy Coding!
:)


你可以输入任意数量的查询在存储过程中。

检查您是否传递了正确的查询参数以删除该行,并且该行存在于表中。
You can put in as many queries as you like in a stored procedure.
Check that you are passing the right query parameters to delete the row and that the row exists in the table.


没有看到您的查询或表格结构,很难给你一个明确的答案......除了Abhinav S所说的,由于行上的键约束(主键/外键),删除查询可能也失败了你想删除。
Without seeing your queries or table structures, it''s difficult to give you a definitive answer... in addition to what Abhinav S says, it might also be that the delete query is failing due to key constraints (primary key/foreign key) on the row you are trying to delete.


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

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