• <legend id='MD3wq'><style id='MD3wq'><dir id='MD3wq'><q id='MD3wq'></q></dir></style></legend>

  • <tfoot id='MD3wq'></tfoot>
  • <small id='MD3wq'></small><noframes id='MD3wq'>

      <i id='MD3wq'><tr id='MD3wq'><dt id='MD3wq'><q id='MD3wq'><span id='MD3wq'><b id='MD3wq'><form id='MD3wq'><ins id='MD3wq'></ins><ul id='MD3wq'></ul><sub id='MD3wq'></sub></form><legend id='MD3wq'></legend><bdo id='MD3wq'><pre id='MD3wq'><center id='MD3wq'></center></pre></bdo></b><th id='MD3wq'></th></span></q></dt></tr></i><div id='MD3wq'><tfoot id='MD3wq'></tfoot><dl id='MD3wq'><fieldset id='MD3wq'></fieldset></dl></div>
        • <bdo id='MD3wq'></bdo><ul id='MD3wq'></ul>

        如何在存储过程中使用插入删除表?

        How use inserteddeleted table in stored procedure?(如何在存储过程中使用插入删除表?)
            <bdo id='MdMXb'></bdo><ul id='MdMXb'></ul>

              <small id='MdMXb'></small><noframes id='MdMXb'>

              <tfoot id='MdMXb'></tfoot>

                <legend id='MdMXb'><style id='MdMXb'><dir id='MdMXb'><q id='MdMXb'></q></dir></style></legend>
                <i id='MdMXb'><tr id='MdMXb'><dt id='MdMXb'><q id='MdMXb'><span id='MdMXb'><b id='MdMXb'><form id='MdMXb'><ins id='MdMXb'></ins><ul id='MdMXb'></ul><sub id='MdMXb'></sub></form><legend id='MdMXb'></legend><bdo id='MdMXb'><pre id='MdMXb'><center id='MdMXb'></center></pre></bdo></b><th id='MdMXb'></th></span></q></dt></tr></i><div id='MdMXb'><tfoot id='MdMXb'></tfoot><dl id='MdMXb'><fieldset id='MdMXb'></fieldset></dl></div>
                    <tbody id='MdMXb'></tbody>
                1. 本文介绍了如何在存储过程中使用插入删除表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我为几个表创建了触发器.触发器具有相同的逻辑.我想使用一个通用的存储过程.但我不知道如何使用 inserteddeleted 表.

                  I creating triggers for several tables. The triggers have same logic. I will want to use a common stored procedure. But I don't know how work with inserted and deleted table.

                  示例:

                  SET @FiledId = (SELECT FiledId FROM inserted)
                  begin tran
                     update table with (serializable) set DateVersion = GETDATE()
                     where FiledId = @FiledId
                  
                     if @@rowcount = 0
                     begin
                        insert table (FiledId) values (@FiledId)
                     end
                  commit tran
                  

                  推荐答案

                  您可以使用 表值参数 用于存储从触发器插入/删除的值,并将其传递给 proc.例如,如果您在 proc 中只需要唯一的 FileID's:

                  You can use a table valued parameter to store the inserted / deleted values from triggers, and pass it across to the proc. e.g., if all you need in your proc is the UNIQUE FileID's:

                  CREATE TYPE FileIds AS TABLE
                  (
                      FileId INT
                  );
                  
                  -- Create the proc to use the type as a TVP
                  CREATE PROC commonProc(@FileIds AS FileIds READONLY)
                      AS
                      BEGIN
                          UPDATE at
                              SET at.DateVersion = CURRENT_TIMESTAMP
                          FROM ATable at
                              JOIN @FileIds fi
                              ON at.FileID = fi.FileID;
                      END
                  

                  然后从触发器中传递插入/删除的 id,例如:

                  And then pass the inserted / deleted ids from the trigger, e.g.:

                  CREATE TRIGGER MyTrigger ON SomeTable FOR INSERT
                  AS
                      BEGIN
                          DECLARE @FileIds FileIDs;
                          INSERT INTO @FileIds(FileID)
                              SELECT DISTINCT FileID FROM INSERTED;
                          EXEC commonProc @FileIds;
                      END;
                  

                  这篇关于如何在存储过程中使用插入删除表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Accessing another user#39;s table within an Oracle Stored Procedure(在 Oracle 存储过程中访问另一个用户的表)
                  Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32)(超出最大存储过程、函数、触发器或视图嵌套级别(限制 32))
                  How to View Oracle Stored Procedure using SQLPlus?(如何使用 SQLPlus 查看 Oracle 存储过程?)
                  How to debug stored procedure in VS 2015?(如何在 VS 2015 中调试存储过程?)
                  How to Pass Java List of Objects to Oracle Stored Procedure Using MyBatis?(如何使用 MyBatis 将 Java 对象列表传递给 Oracle 存储过程?)
                  Set the variable result, from query(设置变量结果,来自查询)
                  <i id='KNEyq'><tr id='KNEyq'><dt id='KNEyq'><q id='KNEyq'><span id='KNEyq'><b id='KNEyq'><form id='KNEyq'><ins id='KNEyq'></ins><ul id='KNEyq'></ul><sub id='KNEyq'></sub></form><legend id='KNEyq'></legend><bdo id='KNEyq'><pre id='KNEyq'><center id='KNEyq'></center></pre></bdo></b><th id='KNEyq'></th></span></q></dt></tr></i><div id='KNEyq'><tfoot id='KNEyq'></tfoot><dl id='KNEyq'><fieldset id='KNEyq'></fieldset></dl></div>

                  <small id='KNEyq'></small><noframes id='KNEyq'>

                  <legend id='KNEyq'><style id='KNEyq'><dir id='KNEyq'><q id='KNEyq'></q></dir></style></legend>
                    <bdo id='KNEyq'></bdo><ul id='KNEyq'></ul>

                      1. <tfoot id='KNEyq'></tfoot>

                              <tbody id='KNEyq'></tbody>