{"id":1168,"date":"2010-12-06T14:02:46","date_gmt":"2010-12-06T13:02:46","guid":{"rendered":"http:\/\/www.galhano.com\/blog\/?p=1168"},"modified":"2010-12-06T14:03:17","modified_gmt":"2010-12-06T13:03:17","slug":"insert-multiple-rows-in-sql-server","status":"publish","type":"post","link":"https:\/\/galhano.com\/blog\/?p=1168","title":{"rendered":"Insert Multiple Rows in SQL Server"},"content":{"rendered":"<p>In SQL Server 2005, in order to insert 3 rows to a table, you had to run 3 INSERT statements:<\/p>\n<div style=\"font-size: 10pt; background: none repeat scroll 0% 0% white; color: black; font-family: consolas;\">\n<p style=\"margin: 0px; padding-left: 30px;\"><span style=\"color: blue;\">insert into <\/span>Customers (<span style=\"color: blue;\">Name<\/span>, City, Phone) <span style=\"color: blue;\">values <\/span>(<span style=\"color: #a31515;\">&#8216;Customer #1&#8217;<\/span>, <span style=\"color: #a31515;\">&#8216;Jerusalem&#8217;<\/span>, <span style=\"color: #a31515;\">&#8216;2343245&#8217;<\/span>)<\/p>\n<p style=\"margin: 0px; padding-left: 30px;\"><span style=\"color: blue;\">insert into <\/span>Customers (<span style=\"color: blue;\">Name<\/span>, City, Phone) <span style=\"color: blue;\">values <\/span>(<span style=\"color: #a31515;\">&#8216;Customer #2&#8217;<\/span>, <span style=\"color: #a31515;\">&#8216;Tel Aviv&#8217;<\/span>, <span style=\"color: #a31515;\">&#8216;0987345&#8217;<\/span>)<\/p>\n<p style=\"margin: 0px; padding-left: 30px;\"><span style=\"color: blue;\">insert into <\/span>Customers (<span style=\"color: blue;\">Name<\/span>, City, Phone) <span style=\"color: blue;\">values <\/span>(<span style=\"color: #a31515;\">&#8216;Customer #3&#8217;<\/span>, <span style=\"color: #a31515;\">&#8216;Haifa&#8217;<\/span>, <span style=\"color: #a31515;\">&#8216;275466&#8217;<\/span>)<\/p>\n<\/div>\n<p>In <a href=\"http:\/\/blogs.microsoft.co.il\/blogs\/bursteg\/archive\/tags\/SQL+Server+2008\/default.aspx\">SQL Server 2008<\/a>, you can <strong>insert multiple rows<\/strong> in a single insert statement that takes  a number of value arrays:<\/p>\n<div style=\"font-size: 10pt; background: none repeat scroll 0% 0% white; color: black; font-family: consolas;\">\n<p style=\"margin: 0px; padding-left: 30px;\"><span style=\"color: blue;\">insert into <\/span>Customers (<span style=\"color: blue;\">Name<\/span>, City, Phone)<\/p>\n<p style=\"margin: 0px; padding-left: 30px;\"><span style=\"color: blue;\">values<\/span><\/p>\n<p style=\"margin: 0px; padding-left: 30px;\">(<span style=\"color: #a31515;\">&#8216;Customer #1&#8217;<\/span>, <span style=\"color: #a31515;\">&#8216;Jerusalem&#8217;<\/span>, <span style=\"color: #a31515;\">&#8216;2343245&#8217;<\/span>),<\/p>\n<p style=\"margin: 0px; padding-left: 30px;\">(<span style=\"color: #a31515;\">&#8216;Customer #2&#8217;<\/span>, <span style=\"color: #a31515;\">&#8216;Tel Aviv&#8217;<\/span>, <span style=\"color: #a31515;\">&#8216;0987345&#8217;<\/span>),<\/p>\n<p style=\"margin: 0px; padding-left: 30px;\">(<span style=\"color: #a31515;\">&#8216;Customer #3&#8217;<\/span>, <span style=\"color: #a31515;\">&#8216;Haifa&#8217;<\/span>, <span style=\"color: #a31515;\">&#8216;275466&#8217;<\/span>)<\/p>\n<p style=\"margin: 0px; padding-left: 30px;\">\n<p style=\"margin: 0px;\">\n<p style=\"margin: 0px;\">\n<p style=\"margin: 0px;\"><a href=\"http:\/\/blogs.microsoft.co.il\/blogs\/bursteg\/archive\/2007\/12\/05\/sql-server-2008-t-sql-insert-multiple-rows.aspx\">Source link<\/a><\/p>\n<p style=\"margin: 0px;\">\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In SQL Server 2005, in order to insert 3 rows to a table, you had to run 3 INSERT statements: insert into Customers (Name, City, Phone) values (&#8216;Customer #1&#8217;, &#8216;Jerusalem&#8217;, &#8216;2343245&#8217;) insert into Customers (Name, City, Phone) values (&#8216;Customer #2&#8217;, &#8216;Tel Aviv&#8217;, &#8216;0987345&#8217;) insert into Customers (Name, City, Phone) values (&#8216;Customer #3&#8217;, &#8216;Haifa&#8217;, &#8216;275466&#8217;) In [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"close","ping_status":"close","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,9,104],"tags":[179,121],"class_list":["post-1168","post","type-post","status-publish","format-standard","hentry","category-microsoft","category-sql-server","category-transact-sql","tag-sql","tag-t-sql","author-admin"],"_links":{"self":[{"href":"https:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1168","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/galhano.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1168"}],"version-history":[{"count":2,"href":"https:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1168\/revisions"}],"predecessor-version":[{"id":1170,"href":"https:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1168\/revisions\/1170"}],"wp:attachment":[{"href":"https:\/\/galhano.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/galhano.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1168"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/galhano.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}