{"id":42176,"date":"2021-08-31T16:57:43","date_gmt":"2021-08-31T16:57:43","guid":{"rendered":"https:\/\/www.oracletutoring.ca\/blog\/?p=42176"},"modified":"2021-08-31T16:57:44","modified_gmt":"2021-08-31T16:57:44","slug":"sql-server-triggers-rows-affected","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/sql-server-triggers-rows-affected\/","title":{"rendered":"SQL Server: triggers: rows affected"},"content":{"rendered":"\n<h2>Self-tutoring about SQL Server: the tutor mentions a potential peculiarity.<\/h2>\n<p>\nLet&#8217;s imagine there&#8217;s a trigger that updates a row just inserted. Performing an insert on such a table today, I got the message\n<\/p>\n<p style=\"font-family:monospace\">\nQuery succeeded: Affected rows: 2<\/p>\n<p>Yet, to my mind, only one row was affected: the freshly inserted one.<\/p>\n<p>I checked the table and found that, in fact, no previous rows had been changed; the only change to it, as hoped, was the newly inserted row. So why would rows affected be 2?<\/p>\n<p>I decided that SQL Server may count each new operation as a change to a row. The insert, then the trigger, it may consider as separate row operations. Therefore, 2 rows are affected means, in this case, that one row is affected twice.<\/p>\n<p>That&#8217;s my suspicion, anyway.<\/p>\nJack of <a href=\"https:\/\/www.oracletutoring.ca\">Oracle Tutoring by Jack and Diane,<\/a> Campbell River, BC.\n","protected":false},"excerpt":{"rendered":"<p>Self-tutoring about SQL Server: the tutor mentions a potential peculiarity. Let&#8217;s imagine there&#8217;s a trigger that updates a row just inserted. Performing an insert on such a table today, I got the message Query succeeded: Affected rows: 2 Yet, to &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/sql-server-triggers-rows-affected\/\"> <span class=\"screen-reader-text\">SQL Server: triggers: rows affected<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3025],"tags":[],"class_list":["post-42176","post","type-post","status-publish","format-standard","hentry","category-sql"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/42176","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/comments?post=42176"}],"version-history":[{"count":2,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/42176\/revisions"}],"predecessor-version":[{"id":42178,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/42176\/revisions\/42178"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=42176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=42176"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=42176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}