存储过程中的多值插入,删除和更新&触发 [英] multiple value insert ,delete and update in store procedure & trigger

查看:146
本文介绍了存储过程中的多值插入,删除和更新&触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了所有插入,删除和upadte查询,因​​为单行受影响



i已尝试插入MULTIROW插入,删除和更新我感到困惑,大部分参考是给予像



插入()

插入()

Insert()用于删除相同的程序< br $> b $ b

删除()

删除()

删除()



operations.this多行插入和删除用于存储过程和触发器创建



所以我需要清楚解释多记录插入,多记录删除,程序和触发器的多记录更新

i tried all insert, delete and upadte queries as single rows affected

i have tried insert MULTIROW insertion,deletion and updation i get confused, most of the refernces are give as like

Insert()
Insert()
Insert() for same procedure for delete

delete()
delete()
delete()

operations.this multi row insertion and deletion used for store procedure and trigger creation

so i need clear explaination about multi record insert,multi record delete, multi record update for procedure and trigger

推荐答案

这是T-SQL文档中的所有内容:



更新( http://msdn.microsoft.com/en-us/library/ms177523.aspx [ ^ ]):

对于WHERE子句(或FROM子句连接)定义的一组行,更新查询总是有效地用于多行。
It is all there in the T-SQL documentation:

Update (http://msdn.microsoft.com/en-us/library/ms177523.aspx[^]):
An update query is always effectively for multiple rows for a set of rows defined by the WHERE clause (or FROM clause join).
UPDATE table set field = value

将更新表中的每一行,因为没有WHERE子句或join来限制集合。



删除 http://msdn.microsoft.com/en-us/library/ms189835。 aspx [ ^ ]) :

删除实际上与更新相同,语法上有一些细微差别。

will update every row in the table because there is no WHERE clause or join to limit the set.

Delete http://msdn.microsoft.com/en-us/library/ms189835.aspx[^]):
Delete is effectively the same as update with some small differences in syntax.

DELETE FROM table

将删除该表中的所有行。



插入(http://msdn.microsoft.com/en-us/library/ms174335.aspx [ ^ ]):

这是例外情况最简单的INSERT添加一行,并且没有简单INSERT的WHERE子句的概念(您正在添加数据,因此WHERE不适用)。要使INSERT添加多行,您必须有一个sub-select子句来选择要添加的集合(可能有一个WHERE子句和/或连接),或者有一个命令的形式来批处理一系列有效的单个行插入(例如):

will delete all rows in that table.

Insert (http://msdn.microsoft.com/en-us/library/ms174335.aspx[^]):
This is the exception as the simplest INSERT adds a single row and there is no concept of a WHERE clause for a simple INSERT (you are adding data so WHERE does not apply). To make an INSERT add multiple rows you must have either a sub-select clause to select the set to be added (which may have a WHERE clause and/or joins) or there is a form of the command to batch a series of effectively single row inserts(e.g.):

INSERT into table (value_A1, value_B1, value_C1), (value_A2, value_B2, value_C2)

插入两行。



你提到触发器。触发器具有插入和已删除的特殊表,插入触发器具有已插入中的新行,删除触发器具有已删除中的已删除行,并且更新触发器具有已插入中的新值和旧值删除(两者都出现未更改的值)。您可以像使用任何其他表一样使用这些特殊表执行连接,并且它们与触发器适用的表共享相同的模式。



使用子的示例多行的子句:

inserts two rows.

You mention triggers. Triggers have special tables "inserted" and "deleted", insert triggers have the new rows in "inserted", delete triggers have the deleted rows in "deleted" and update triggers have the new values in "inserted" and the old values in "deleted" (unaltered values appear in both). You can perform joins using these special tables just as you would any other tables and they share the same schema as the table to which the trigger applies.

Examples using sub-clauses for multiple rows:

UPDATE table1
SET field1 = value
FROM table1 INNER JOIN table2 ON table1.JoinField1 = table2.JoinField2




DELETE 
FROM table1
<pre>WHERE FilterField IN (SELECT FilterField FROM table2)




INSERT INTO table1 (field1, field2, field3)
SELECT fielda, derivedvalueb, fieldc FROM table2

这涵盖了您提出的一般问题。如果您遇到特定问题,则需要共享您尝试过的代码,并解释您所希望的行为与结果的不同之处。使用改进问题功能添加细节。



祝你好运!

This covers the questions you raise in general. If you are having a specific problem, you need to share the code you tried and explain how the behaviour you desire differs from the outcome. Use the improve question function to add detail.

Good luck!


这篇关于存储过程中的多值插入,删除和更新&amp;触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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