{"id":1461,"date":"2019-11-05T15:27:49","date_gmt":"2019-11-05T18:27:49","guid":{"rendered":"https:\/\/www.franklinjr.com\/blog\/?p=1461"},"modified":"2019-11-21T08:15:22","modified_gmt":"2019-11-21T11:15:22","slug":"popular-dados-em-uma-tabela-sql-server","status":"publish","type":"post","link":"https:\/\/www.franklinjr.com\/blog\/index.php\/2019\/11\/05\/popular-dados-em-uma-tabela-sql-server\/","title":{"rendered":"Popular dados em uma tabela sql server"},"content":{"rendered":"\n<p>Caso precise fazer algum tipo de teste que seja necess\u00e1rio popular dados em uma tabela SQL Server, \u00e9 poss\u00edvel executar o seguinte script para criar a tabela e j\u00e1 &#8216;inflar&#8217; com os dados para testes. Os campos ser\u00e3o populados com datas aleat\u00f3rias.<\/p>\n\n\n\n<p>SQL da cria\u00e7\u00e3o da tabela<\/p>\n\n\n\n<pre lang=\"sql\">\nCREATE TABLE dbo.TestTableSize\n(\n MyKeyField VARCHAR(10) NOT NULL,\n MyDate1 DATETIME NOT NULL,\n MyDate2 DATETIME NOT NULL,\n MyDate3 DATETIME NOT NULL,\n MyDate4 DATETIME NOT NULL,\n MyDate5 DATETIME NOT NULL\n)\n<\/pre>\n\n\n\n<p>SQL para popular os dados na tabela rec\u00e9m criada <\/p>\n\n\n\n<pre lang=\"sql\">\n-- Declara os tipos de vari\u00e1veis que iremos utilizar\nDECLARE @RowCount INT\nDECLARE @RowString VARCHAR(10)\nDECLARE @Random INT\nDECLARE @Upper INT\nDECLARE @Lower INT\nDECLARE @InsertDate DATETIME\n\n\nSET @Lower = -730 --configura a data at\u00e9 2 anos para tr\u00e1s(365*2)\nSET @Upper = -1 --configura a data no m\u00e1ximo at\u00e9 1 dia atr\u00e1s\nSET @RowCount = 0 --configura a contagem de linhas\n\n-- while para popular os dados na tabela\nWHILE @RowCount < 3000000\nBEGIN\n\t-- paranau\u00ea para calcular a data para inser\u00e7\u00e3o\n\tSET @RowString = CAST(@RowCount AS VARCHAR(10))\n\tSELECT @Random = ROUND(((@Upper - @Lower -1) * RAND() + @Lower), 0)\n\tSET @InsertDate = DATEADD(dd, @Random, GETDATE())\n\t\n\tINSERT INTO TestTableSize\n\t\t(MyKeyField\n\t\t,MyDate1\n\t\t,MyDate2\n\t\t,MyDate3\n\t\t,MyDate4\n\t\t,MyDate5)\n\tVALUES\n\t\t(REPLICATE('0', 10 - DATALENGTH(@RowString)) + @RowString\n\t\t, @InsertDate\n\t\t,DATEADD(dd, 1, @InsertDate)\n\t\t,DATEADD(dd, 2, @InsertDate)\n\t\t,DATEADD(dd, 3, @InsertDate)\n\t\t,DATEADD(dd, 4, @InsertDate))\n\n\tSET @RowCount = @RowCount + 1\nEND\n<\/pre>\n\n\n\n<p>Fiz um resum\u00e3o do link que encontrei:  <\/p>\n\n\n\n<p><a href=\"https:\/\/mitchelsellers.com\/blog\/article\/creating-random-sql-server-test-data \">https:\/\/mitchelsellers.com\/blog\/article\/creating-random-sql-server-test-data <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Caso precise fazer algum tipo de teste que seja necess\u00e1rio popular dados em uma tabela SQL Server, \u00e9 poss\u00edvel executar o seguinte script para criar a tabela e j\u00e1 &#8216;inflar&#8217; com os dados para testes. Os campos ser\u00e3o populados com datas aleat\u00f3rias. SQL da cria\u00e7\u00e3o da tabela CREATE TABLE dbo.TestTableSize ( MyKeyField VARCHAR(10) NOT NULL, [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[506,441],"tags":[],"class_list":["post-1461","post","type-post","status-publish","format-standard","hentry","category-sql-2","category-sql-server-2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\r\n<title>Popular dados em uma tabela sql server - Franklin Jr.<\/title>\r\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\r\n<link rel=\"canonical\" href=\"https:\/\/www.franklinjr.com\/blog\/index.php\/2019\/11\/05\/popular-dados-em-uma-tabela-sql-server\/\" \/>\r\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.franklinjr.com\/blog\/index.php\/2019\/11\/05\/popular-dados-em-uma-tabela-sql-server\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"In\u00edcio\",\"item\":\"https:\/\/www.franklinjr.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Popular dados em uma tabela sql server\"}]}]}<\/script>\r\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Popular dados em uma tabela sql server - Franklin Jr.","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":"https:\/\/www.franklinjr.com\/blog\/index.php\/2019\/11\/05\/popular-dados-em-uma-tabela-sql-server\/","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BreadcrumbList","@id":"https:\/\/www.franklinjr.com\/blog\/index.php\/2019\/11\/05\/popular-dados-em-uma-tabela-sql-server\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"In\u00edcio","item":"https:\/\/www.franklinjr.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Popular dados em uma tabela sql server"}]}]}},"_links":{"self":[{"href":"https:\/\/www.franklinjr.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1461","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.franklinjr.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.franklinjr.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.franklinjr.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.franklinjr.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=1461"}],"version-history":[{"count":5,"href":"https:\/\/www.franklinjr.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1461\/revisions"}],"predecessor-version":[{"id":1474,"href":"https:\/\/www.franklinjr.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1461\/revisions\/1474"}],"wp:attachment":[{"href":"https:\/\/www.franklinjr.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=1461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.franklinjr.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=1461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.franklinjr.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=1461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}