{"id":34,"date":"2014-01-02T21:27:26","date_gmt":"2014-01-02T13:27:26","guid":{"rendered":"http:\/\/suherman.asia\/w2\/?p=34"},"modified":"2014-08-26T12:21:17","modified_gmt":"2014-08-26T04:21:17","slug":"inserting-data-into-2-tables-with-1-statement-without-trigger","status":"publish","type":"post","link":"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html","title":{"rendered":"Inserting Data into 2 Tables with 1 Statement without Trigger"},"content":{"rendered":"<p>Biasanya kita menggunakan trigger untuk dapat melakukan memasukkan data ke dalam 2 tabel yang berbeda sekaligus. 1 tabel target yang akan dimasukkan data yang kemudian dibuatkan trigger yang kemudian trigger tersebut akan melakukan proses insert ke tabel ke 2.<\/p>\n<p>Namun dalam perkembangannya, Insert Statement saat ini di memiliki sub-klausa OUTPUT. dengan memanfaatkan sub-klausa OUTPUT tersebut kita dapat membuat 1 buah statement insert yang dapat melakukan insert data ke 2 buah tabel sekaligus.<\/p>\n<p>Mari kita coba praktekkan bersama-sama :<\/p>\n<p>contoh kasusnya adalah sebagai berikut, di departemen TI memiliki policy bahwa setiap penambahan user baru pada sebuah aplikasi harus melakukan penggantian password dalam kurun waktu 7 hari. dalam 7 hari tersebut, user akan selalu diingatkan oleh sistem setiap login untuk pengganti passwordnya sampai user tersebut mengganti password.<\/p>\n<p>Pertama kita akan membuat 2 buah tabel yaitu tabel DftrUser dan tabel TblPengingat<\/p>\n<pre class=\"lang:tsql decode:true \">USE AdventureWorks;\r\nGO \r\nCREATE SCHEMA [Pengguna] AUTHORIZATION dbo;\r\nGO \r\nCREATE TABLE [Pengguna].[DftrUser]\r\n    (       \r\n[PenggunaID] [int] IDENTITY(1,1) NOT NULL,\r\n       [Nama] VARCHAR(30) NOT NULL,\r\n       [Password] VARCHAR(30) NOT NULL,\r\n         CONSTRAINT [PK_PenggunaID] PRIMARY KEY CLUSTERED\r\n             ( \r\n              [PenggunaID] ASC\r\n            )ON [PRIMARY]\r\n    ) ON [PRIMARY];\r\nGO \r\n\r\nCREATE TABLE [Pengguna].[TblPengingat]\r\n    (\r\n        [PengingatID] [int] IDENTITY(1,1) NOT NULL,\r\n       [PenggunaID] [int] NOT NULL,\r\n       [Tgl] DATETIME NOT NULL,\r\n       [SttPengguna] CHAR(1) NOT NULL,\r\n         CONSTRAINT [PK_PengingatID] PRIMARY KEY CLUSTERED\r\n             (\r\n               [PengingatID] ASC\r\n            )ON [PRIMARY]\r\n    ) ON [PRIMARY];\r\nGO<\/pre>\n<p>Sekarang kita coba untuk memasukkan data-data yang diperlukan untuk proses diatas dengan menggunakan 1 buah statement tanpa menggunakan trigger<\/p>\n<pre class=\"lang:tsql decode:true \">INSERT INTO [Pengguna].[DftrUser] ( Nama, password )\r\nOUTPUT INSERTED.PenggunaID, \r\nDATEADD(d,7,GETDATE()),'0'INTO[Pengguna].[TblPengingat] \r\n   (\r\n        PenggunaID,\r\n        Tgl,\r\n        SttPengguna\r\n    )\r\nVALUES  ( 'Suherman','K4taSand1');<\/pre>\n<p>dan berikut hasilnya :<\/p>\n<pre class=\"lang:tsql decode:true \">select * from [Pengguna].[DftrUser]\r\nGo\r\nselect * from [Pengguna].[TblPengingat]\r\nGo<\/pre>\n<p><a href=\"http:\/\/mugi.or.id\/cfs-file.ashx\/__key\/CommunityServer.Blogs.Components.WeblogFiles\/suherman\/image_5F00_3CB42846.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;\" title=\"image\" src=\"http:\/\/mugi.or.id\/cfs-file.ashx\/__key\/CommunityServer.Blogs.Components.WeblogFiles\/suherman\/image_5F00_thumb_5F00_49AE0857.png\" alt=\"image\" width=\"475\" height=\"149\" border=\"0\" \/><\/a><\/p>\n<p>tampak bahwa data telah masuk ke kedua tabel tersebut dengan hanya menggunakan 1 statement DML saja.<\/p>\n<p>Demikian semoga bermanfaat.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Biasanya kita menggunakan trigger untuk dapat melakukan memasukkan data ke dalam 2 tabel yang berbeda sekaligus. 1 tabel target yang akan dimasukkan data yang kemudian dibuatkan trigger yang kemudian trigger tersebut akan melakukan proses insert ke tabel ke 2. Namun dalam perkembangannya, Insert Statement saat ini di memiliki sub-klausa OUTPUT. \u2026<\/p>\n<p class=\"continue-reading-button\"> <a class=\"continue-reading-link\" href=\"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html\">Continue reading<i class=\"crycon-right-dir\"><\/i><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[14],"class_list":["post-34","post","type-post","status-publish","format-standard","hentry","category-sql-server","tag-t-sql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Inserting Data into 2 Tables with 1 Statement without Trigger - Suherman Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Inserting Data into 2 Tables with 1 Statement without Trigger - Suherman Blog\" \/>\n<meta property=\"og:description\" content=\"Biasanya kita menggunakan trigger untuk dapat melakukan memasukkan data ke dalam 2 tabel yang berbeda sekaligus. 1 tabel target yang akan dimasukkan data yang kemudian dibuatkan trigger yang kemudian trigger tersebut akan melakukan proses insert ke tabel ke 2. Namun dalam perkembangannya, Insert Statement saat ini di memiliki sub-klausa OUTPUT. \u2026 Continue reading\" \/>\n<meta property=\"og:url\" content=\"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html\" \/>\n<meta property=\"og:site_name\" content=\"Suherman Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/emantin34\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/emantin34\" \/>\n<meta property=\"article:published_time\" content=\"2014-01-02T13:27:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-08-26T04:21:17+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/mugi.or.id\/cfs-file.ashx\/__key\/CommunityServer.Blogs.Components.WeblogFiles\/suherman\/image_5F00_thumb_5F00_49AE0857.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html#article\",\"isPartOf\":{\"@id\":\"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html\"},\"author\":{\"name\":\"admin\",\"@id\":\"http:\/\/suherman.asia\/w2\/#\/schema\/person\/63654a129ee88012961c1a00415967dc\"},\"headline\":\"Inserting Data into 2 Tables with 1 Statement without Trigger\",\"datePublished\":\"2014-01-02T13:27:26+00:00\",\"dateModified\":\"2014-08-26T04:21:17+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html\"},\"wordCount\":176,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/suherman.asia\/w2\/#\/schema\/person\/63654a129ee88012961c1a00415967dc\"},\"image\":{\"@id\":\"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html#primaryimage\"},\"thumbnailUrl\":\"http:\/\/mugi.or.id\/cfs-file.ashx\/__key\/CommunityServer.Blogs.Components.WeblogFiles\/suherman\/image_5F00_thumb_5F00_49AE0857.png\",\"keywords\":[\"T-SQL\"],\"articleSection\":[\"SQL Server\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html\",\"url\":\"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html\",\"name\":\"Inserting Data into 2 Tables with 1 Statement without Trigger - Suherman Blog\",\"isPartOf\":{\"@id\":\"http:\/\/suherman.asia\/w2\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html#primaryimage\"},\"image\":{\"@id\":\"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html#primaryimage\"},\"thumbnailUrl\":\"http:\/\/mugi.or.id\/cfs-file.ashx\/__key\/CommunityServer.Blogs.Components.WeblogFiles\/suherman\/image_5F00_thumb_5F00_49AE0857.png\",\"datePublished\":\"2014-01-02T13:27:26+00:00\",\"dateModified\":\"2014-08-26T04:21:17+00:00\",\"breadcrumb\":{\"@id\":\"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html#primaryimage\",\"url\":\"http:\/\/mugi.or.id\/cfs-file.ashx\/__key\/CommunityServer.Blogs.Components.WeblogFiles\/suherman\/image_5F00_thumb_5F00_49AE0857.png\",\"contentUrl\":\"http:\/\/mugi.or.id\/cfs-file.ashx\/__key\/CommunityServer.Blogs.Components.WeblogFiles\/suherman\/image_5F00_thumb_5F00_49AE0857.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/suherman.asia\/w2\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Inserting Data into 2 Tables with 1 Statement without Trigger\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/suherman.asia\/w2\/#website\",\"url\":\"http:\/\/suherman.asia\/w2\/\",\"name\":\"Suherman Blog\",\"description\":\"Just Another Geek Site\",\"publisher\":{\"@id\":\"http:\/\/suherman.asia\/w2\/#\/schema\/person\/63654a129ee88012961c1a00415967dc\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/suherman.asia\/w2\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"http:\/\/suherman.asia\/w2\/#\/schema\/person\/63654a129ee88012961c1a00415967dc\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/suherman.asia\/w2\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/eed6f889b4c2af2a8c18cb3bf63de6a4?s=96&d=retro&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/eed6f889b4c2af2a8c18cb3bf63de6a4?s=96&d=retro&r=g\",\"caption\":\"admin\"},\"logo\":{\"@id\":\"http:\/\/suherman.asia\/w2\/#\/schema\/person\/image\/\"},\"sameAs\":[\"http:\/\/suherman.asia\",\"https:\/\/www.facebook.com\/emantin34\",\"https:\/\/x.com\/emantin34\"],\"url\":\"http:\/\/suherman.asia\/w2\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Inserting Data into 2 Tables with 1 Statement without Trigger - Suherman Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html","og_locale":"en_US","og_type":"article","og_title":"Inserting Data into 2 Tables with 1 Statement without Trigger - Suherman Blog","og_description":"Biasanya kita menggunakan trigger untuk dapat melakukan memasukkan data ke dalam 2 tabel yang berbeda sekaligus. 1 tabel target yang akan dimasukkan data yang kemudian dibuatkan trigger yang kemudian trigger tersebut akan melakukan proses insert ke tabel ke 2. Namun dalam perkembangannya, Insert Statement saat ini di memiliki sub-klausa OUTPUT. \u2026 Continue reading","og_url":"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html","og_site_name":"Suherman Blog","article_publisher":"https:\/\/www.facebook.com\/emantin34","article_author":"https:\/\/www.facebook.com\/emantin34","article_published_time":"2014-01-02T13:27:26+00:00","article_modified_time":"2014-08-26T04:21:17+00:00","og_image":[{"url":"http:\/\/mugi.or.id\/cfs-file.ashx\/__key\/CommunityServer.Blogs.Components.WeblogFiles\/suherman\/image_5F00_thumb_5F00_49AE0857.png","type":"","width":"","height":""}],"author":"admin","twitter_misc":{"Written by":"admin","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html#article","isPartOf":{"@id":"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html"},"author":{"name":"admin","@id":"http:\/\/suherman.asia\/w2\/#\/schema\/person\/63654a129ee88012961c1a00415967dc"},"headline":"Inserting Data into 2 Tables with 1 Statement without Trigger","datePublished":"2014-01-02T13:27:26+00:00","dateModified":"2014-08-26T04:21:17+00:00","mainEntityOfPage":{"@id":"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html"},"wordCount":176,"commentCount":0,"publisher":{"@id":"http:\/\/suherman.asia\/w2\/#\/schema\/person\/63654a129ee88012961c1a00415967dc"},"image":{"@id":"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html#primaryimage"},"thumbnailUrl":"http:\/\/mugi.or.id\/cfs-file.ashx\/__key\/CommunityServer.Blogs.Components.WeblogFiles\/suherman\/image_5F00_thumb_5F00_49AE0857.png","keywords":["T-SQL"],"articleSection":["SQL Server"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html#respond"]}]},{"@type":"WebPage","@id":"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html","url":"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html","name":"Inserting Data into 2 Tables with 1 Statement without Trigger - Suherman Blog","isPartOf":{"@id":"http:\/\/suherman.asia\/w2\/#website"},"primaryImageOfPage":{"@id":"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html#primaryimage"},"image":{"@id":"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html#primaryimage"},"thumbnailUrl":"http:\/\/mugi.or.id\/cfs-file.ashx\/__key\/CommunityServer.Blogs.Components.WeblogFiles\/suherman\/image_5F00_thumb_5F00_49AE0857.png","datePublished":"2014-01-02T13:27:26+00:00","dateModified":"2014-08-26T04:21:17+00:00","breadcrumb":{"@id":"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html#primaryimage","url":"http:\/\/mugi.or.id\/cfs-file.ashx\/__key\/CommunityServer.Blogs.Components.WeblogFiles\/suherman\/image_5F00_thumb_5F00_49AE0857.png","contentUrl":"http:\/\/mugi.or.id\/cfs-file.ashx\/__key\/CommunityServer.Blogs.Components.WeblogFiles\/suherman\/image_5F00_thumb_5F00_49AE0857.png"},{"@type":"BreadcrumbList","@id":"http:\/\/suherman.asia\/w2\/inserting-data-into-2-tables-with-1-statement-without-trigger.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/suherman.asia\/w2"},{"@type":"ListItem","position":2,"name":"Inserting Data into 2 Tables with 1 Statement without Trigger"}]},{"@type":"WebSite","@id":"http:\/\/suherman.asia\/w2\/#website","url":"http:\/\/suherman.asia\/w2\/","name":"Suherman Blog","description":"Just Another Geek Site","publisher":{"@id":"http:\/\/suherman.asia\/w2\/#\/schema\/person\/63654a129ee88012961c1a00415967dc"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/suherman.asia\/w2\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"http:\/\/suherman.asia\/w2\/#\/schema\/person\/63654a129ee88012961c1a00415967dc","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/suherman.asia\/w2\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/eed6f889b4c2af2a8c18cb3bf63de6a4?s=96&d=retro&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/eed6f889b4c2af2a8c18cb3bf63de6a4?s=96&d=retro&r=g","caption":"admin"},"logo":{"@id":"http:\/\/suherman.asia\/w2\/#\/schema\/person\/image\/"},"sameAs":["http:\/\/suherman.asia","https:\/\/www.facebook.com\/emantin34","https:\/\/x.com\/emantin34"],"url":"http:\/\/suherman.asia\/w2\/author\/admin"}]}},"_links":{"self":[{"href":"http:\/\/suherman.asia\/w2\/wp-json\/wp\/v2\/posts\/34","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/suherman.asia\/w2\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/suherman.asia\/w2\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/suherman.asia\/w2\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/suherman.asia\/w2\/wp-json\/wp\/v2\/comments?post=34"}],"version-history":[{"count":3,"href":"http:\/\/suherman.asia\/w2\/wp-json\/wp\/v2\/posts\/34\/revisions"}],"predecessor-version":[{"id":391,"href":"http:\/\/suherman.asia\/w2\/wp-json\/wp\/v2\/posts\/34\/revisions\/391"}],"wp:attachment":[{"href":"http:\/\/suherman.asia\/w2\/wp-json\/wp\/v2\/media?parent=34"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/suherman.asia\/w2\/wp-json\/wp\/v2\/categories?post=34"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/suherman.asia\/w2\/wp-json\/wp\/v2\/tags?post=34"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}