{"id":2242,"date":"2022-06-30T20:00:27","date_gmt":"2022-06-30T11:00:27","guid":{"rendered":"http:\/\/idealive.jp\/blog\/?p=2242"},"modified":"2022-06-30T21:09:35","modified_gmt":"2022-06-30T12:09:35","slug":"%e3%80%90sqlserver%e3%80%91%e3%83%88%e3%83%aa%e3%82%ac%e3%83%bc","status":"publish","type":"post","link":"https:\/\/idealive.jp\/blog\/2022\/06\/30\/%e3%80%90sqlserver%e3%80%91%e3%83%88%e3%83%aa%e3%82%ac%e3%83%bc\/","title":{"rendered":"SQLServer\u30c8\u30ea\u30ac\u30fc"},"content":{"rendered":"<p>\u4eca\u56de\u306f\u696d\u52d9\u306e\u4e00\u90e8\u4f7f\u7528\u3057\u305f\u3067\u30c7\u30fc\u30bf\u6574\u5408\u6027\u3092\u4fdd\u3064\u305f\u3081\u306e\u3010SQLServer\u3011\u30c8\u30ea\u30ac\u30fc\u306b\u3064\u3044\u3066\u8a18\u8f09\u3057\u307e\u3059\u3002<\/p>\n<p>SQLServer\u30c8\u30ea\u30ac\u30fc\u3068\u306f\u2026<br \/>\n\u30c6\u30fc\u30d6\u30eb\u306b\u5bfe\u3057\u3066\u64cd\u4f5c(Insert\u30fbUpdate\u30fb Delete)\u3092\u8d77\u56e0\u3068\u3057\u3066\u81ea\u52d5\u7684\u306b\u5b9f\u884c\u3055\u308c\u308b\u6a5f\u80fd\u3067\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306btable1\u3068table2\u304c\u9023\u52d5\u3057\u3066\u3044\u308b\u30c6\u30fc\u30d6\u30eb\u304c\u3042\u308b\u5834\u5408<\/p>\n<p>table1\uff08id1,seq,column1_1,column1_2\uff09<br \/>\ntable2\uff08id1,key,column2_1,column2_2\uff09<\/p>\n<p>SELECT * FROM table1<br \/>\nLEFT JOIN table2 ON table1.id1 = table2.id1<\/p>\n<p>table1\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u6d88\u3057\u305f\u5834\u5408\u3001\u7d10\u3065\u3044\u3066\u3044\u308btable2\u3092\u6d88\u3059\u4e8b\u304c\u591a\u3044\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u3053\u306e\u5834\u5408\u306b\u3010SQLServer\u3011\u30c8\u30ea\u30ac\u30fc\u3067\u9023\u52d5\u3057\u3066table2\u3082\u6d88\u3059\u3088\u3046\u306b\u4ed5\u8fbc\u3080\uff08\u4e0b\u8a18\u306eSQL\uff09\u3002<\/p>\n<p>CREATE TRIGGER trg1 &#8211;\u2460<br \/>\n  ON [table1] AFTER &#8211;\u2461<br \/>\nDELETE AS BEGIN &#8211;\u2462<br \/>\nDELETE &#8211;\u2463<br \/>\nFROM<br \/>\n  table2<br \/>\nWHERE<br \/>\n  id1 = (SELECT id1 FROM deleted) &#8211;\u2464<br \/>\nEND<\/p>\n<p>\u2460trg1\u306f\u30c8\u30ea\u30ac\u30fc\u306e\u4efb\u610f\u306e\u540d\u524d<br \/>\n\u2461\u5bfe\u8c61\u30c6\u30fc\u30d6\u30eb\uff08table1\uff09\u306b\u5bfe\u3057\u3066\u306e\u30c8\u30ea\u30ac\u30fc<br \/>\n\u2462\u524a\u9664\u5b9f\u884c\u3055\u308c\u305f\u5834\u5408\uff08INSERT\u3084UPDATE\u3067\u3082\u53ef\u80fd\uff09<br \/>\n\u2463\u30c8\u30ea\u30ac\u30fc\u51e6\u7406\u3092\u8a18\u8f09<br \/>\n\u2464\u524a\u9664\u3055\u308c\u308b\u30c6\u30fc\u30d6\u30eb\u60c5\u5831\uff08\u767b\u9332\u30fb\u66f4\u65b0\uff1ainserted\u3001\u524a\u9664\uff1adeleted\uff09<\/p>\n<p>\u7269\u7406\u524a\u9664\u3084\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3059\u308b\u5834\u5408\u306f\u4fbf\u5229\u3060\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u8ad6\u7406\u524a\u9664\u306e\u5834\u5408\u306f\u6761\u4ef6\u306a\u3069\u3044\u308b\u3068\u601d\u3046\u306e\u3067\u96e3\u3057\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u30c8\u30ea\u30ac\u30fc\u4e00\u89a7\u306f\u4e0b\u8a18\u306eSQL\u3067\u95b2\u89a7\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<p>SELECT<br \/>\n  Ob.name AS \u30c6\u30fc\u30d6\u30eb\u540d<br \/>\n  , TR.name AS \u30c8\u30ea\u30ac\u30fc\u540d<br \/>\n  , TE.type_desc AS \u30c8\u30ea\u30ac\u30fc\u64cd\u4f5c<br \/>\n  , Sm.definition<br \/>\nFROM<br \/>\n  sys.triggers TR<br \/>\n  INNER JOIN sys.objects Ob<br \/>\n    ON TR.parent_id = Ob.object_id<br \/>\n  INNER JOIN sys.trigger_events TE<br \/>\n    ON TE.object_id = TR.object_id<br \/>\n  INNER JOIN sys.all_sql_modules Sm<br \/>\n    ON Sm.object_id = TR.object_id<\/p>\n<p>\u30c8\u30ea\u30ac\u30fc\u3092\u524a\u9664\u3057\u305f\u3044\u5834\u5408\u306f\u3053\u3061\u3089\u3002<br \/>\nDROP TRIGGER [\u30c8\u30ea\u30ac\u30fc\u540d]<\/p>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u89e6\u3089\u306a\u304f\u3066\u3088\u3044\u306e\u3068<br \/>\n\u5f71\u97ff\u7bc4\u56f2\u3067\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u5074\u3067\u306e\u5bfe\u5fdc\u6f0f\u308c\u304c\u306a\u304f\u306a\u308b\u3068\u601d\u3044\u307e\u3059\u304c<br \/>\nSQLServer\u306e\u8a2d\u5b9a\u306e\u305f\u3081\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u306a\u3069\u3092\u5fd8\u308c\u306a\u3044\u3088\u3046\u306b\u6ce8\u610f\u3057\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u3067\u3059\u306d\u3002<\/p>\n<p>\u4ee5\u4e0a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u56de\u306f\u696d\u52d9\u306e\u4e00\u90e8\u4f7f\u7528\u3057\u305f\u3067\u30c7\u30fc\u30bf\u6574\u5408\u6027\u3092\u4fdd\u3064\u305f\u3081\u306e\u3010SQLServer\u3011\u30c8\u30ea\u30ac\u30fc\u306b\u3064\u3044\u3066\u8a18\u8f09\u3057\u307e\u3059\u3002 SQLServer\u30c8\u30ea\u30ac\u30fc\u3068\u306f\u2026 \u30c6\u30fc\u30d6\u30eb\u306b\u5bfe\u3057\u3066\u64cd\u4f5c(Insert\u30fbUpdate\u30fb Delete)\u3092\u8d77\u56e0\u3068\u3057\u3066\u81ea\u52d5\u7684&#8230;<a class=\"read-more-link button\" href=\"https:\/\/idealive.jp\/blog\/2022\/06\/30\/%e3%80%90sqlserver%e3%80%91%e3%83%88%e3%83%aa%e3%82%ac%e3%83%bc\/\">\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":7,"featured_media":2245,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,13],"tags":[],"class_list":["post-2242","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sql-server","category-database"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/posts\/2242"}],"collection":[{"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/comments?post=2242"}],"version-history":[{"count":7,"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/posts\/2242\/revisions"}],"predecessor-version":[{"id":2250,"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/posts\/2242\/revisions\/2250"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/media\/2245"}],"wp:attachment":[{"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/media?parent=2242"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/categories?post=2242"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/tags?post=2242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}