{"id":83,"date":"2011-08-27T20:14:36","date_gmt":"2011-08-27T14:44:36","guid":{"rendered":"http:\/\/beginsql.wordpress.com\/?p=83"},"modified":"2011-08-27T20:14:36","modified_gmt":"2011-08-27T14:44:36","slug":"index-misuse-script","status":"publish","type":"post","link":"https:\/\/sqlhints.com\/2011\/08\/27\/index-misuse-script\/","title":{"rendered":"Index misuse Script"},"content":{"rendered":"<p>Below Script can be\u00a0used to create a database PerformanceTraining\u00a0with a\u00a0table Employee. This script populates 5\u00a0Lakh records in the employee table. Note: Copy paste of this script is not working properly, please correct the quotation marks before running it.<\/p>\n<p>CREATE DATABASE PerformanceTraining<br \/>\nGO<br \/>\nUSE PerformanceTraining<br \/>\nGO<br \/>\nCREATE TABLE [Employee](<br \/>\n[EmployeeID] [int] IDENTITY(1,1) NOT NULL,<br \/>\n[FirstName] Varchar(50),<br \/>\n[LastName]\u00a0 Varchar(50),<br \/>\n[City]\u00a0\u00a0\u00a0\u00a0 Varchar(50),<br \/>\n[State]\u00a0 Varchar(40),<br \/>\n[Country]\u00a0\u00a0 VarChar(40),<br \/>\n[BirthDate] datetime,<br \/>\n[MaritalStatus] nchar(1),<br \/>\n[Gender] nchar(1),<br \/>\n[HireDate] datetime,<br \/>\n[CreationDate] datetime,<br \/>\n[ChangeDate] datetime<br \/>\n)<br \/>\nGO<br \/>\nSET NOCOUNT ON<\/p>\n<p>Declare @i\u00a0int,@State varchar(40),@MaritalStatus\u00a0nchar(1),@Gender nchar(1)<br \/>\nSET @i=0<br \/>\nwhile(@i&lt;500000)<br \/>\nBegin<br \/>\nSELECT @i = @i\u00a0+1,@MaritalStatus=&#8217;S&#8217;,@Gender=&#8217;M&#8217;,@State=&#8217;Karnataka&#8217;<\/p>\n<p>if(@i % 2 =0)<br \/>\nselect @MaritalStatus=&#8217;M&#8217;,@Gender=&#8217;F&#8217;,@State=&#8217;Maharashtra&#8217;<\/p>\n<p>INSERT INTO [PerformanceTraining].[dbo].[Employee]<br \/>\n([FirstName],[LastName],[City],<br \/>\n[State],[Country],[BirthDate]<br \/>\n,[MaritalStatus],[Gender],[HireDate]<br \/>\n,[CreationDate],[ChangeDate])<br \/>\nVALUES (&#8216;FirstName&#8217; + CAST(@i\u00a0AS VARCHAR), &#8216;LastName&#8217; + CAST(@i\u00a0AS VARCHAR),&#8217;City&#8217; + CAST(@i AS VARCHAR)<br \/>\n,@State,&#8217;INDIA&#8217;,DATEADD(DAY,@i\/1000,&#8217;01\/01\/1978&#8242;)<br \/>\n,@MaritalStatus,@Gender,DATEADD(DAY,@i\/1000,&#8217;01\/01\/2000 &#8216; + CONVERT(VARCHAR(8),GETDATE(),108))<br \/>\n,DATEADD(DAY,@i\/1000,&#8217;01\/01\/2000&#8242;),DATEADD(DAY,@i\/1000,&#8217;01\/01\/2000&#8217;))<\/p>\n<p>IF @i = 500000<br \/>\nUPDATE dbo.Employee WITH(ROWLOCK)<br \/>\nSET HireDate = &#8216;2001-05-16 &#8216; + CONVERT(VARCHAR(8),GETDATE(),108)<br \/>\nWHERE EmployeeID = @i<\/p>\n<p>end<\/p>\n<p>GO<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Below Script can be\u00a0used to create a database PerformanceTraining\u00a0with a\u00a0table Employee. This script populates 5\u00a0Lakh records in the employee table. Note: Copy paste of this script is not working properly, please correct the quotation marks before running it. CREATE DATABASE PerformanceTraining GO USE PerformanceTraining GO CREATE TABLE [Employee]( [EmployeeID] [int] IDENTITY(1,1) NOT NULL, [FirstName] Varchar(50), &hellip; <a href=\"https:\/\/sqlhints.com\/2011\/08\/27\/index-misuse-script\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Index misuse Script<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[15],"tags":[],"class_list":["post-83","post","type-post","status-publish","format-standard","hentry","category-scripts"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3xNAz-1l","_links":{"self":[{"href":"https:\/\/sqlhints.com\/wp-json\/wp\/v2\/posts\/83","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sqlhints.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sqlhints.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sqlhints.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sqlhints.com\/wp-json\/wp\/v2\/comments?post=83"}],"version-history":[{"count":0,"href":"https:\/\/sqlhints.com\/wp-json\/wp\/v2\/posts\/83\/revisions"}],"wp:attachment":[{"href":"https:\/\/sqlhints.com\/wp-json\/wp\/v2\/media?parent=83"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sqlhints.com\/wp-json\/wp\/v2\/categories?post=83"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sqlhints.com\/wp-json\/wp\/v2\/tags?post=83"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}