Solved

SQL2005 Insert

Posted on 2007-12-05
11
299 Views
Last Modified: 2012-06-21
Please write a sql script that would insert 20,000 records at a go on the below table

CREATE TABLE [dbo].[tb_CCMemberTest](
      [ccm_SID] [int] IDENTITY(10234851,1) NOT FOR REPLICATION NOT NULL,
      [ccm_ccl_SID] [int] NOT NULL,
      [ccm_title] [varchar](50) NULL,
      [ccm_FirstName] [varchar](50) NOT NULL,
      [ccm_MiddleName] [varchar](50) NULL,
      [ccm_LastName] [varchar](50) NOT NULL,
      [ccm_DateOfBirth] [smalldatetime] NULL,
      [ccm_HomeAddress1] [varchar](50) NULL,
      [ccm_HomeAddress2] [varchar](50) NULL,
      [ccm_HomeAddress3] [varchar](50) NULL,
      [ccm_HomeAddress4] [varchar](50) NULL,
      [ccm_HomeAddressTown] [varchar](50) NULL,
      [ccm_HomeAddressCounty] [varchar](50) NULL,
      [ccm_HomeAddressPostCode] [varchar](10) NULL,
      [ccm_HomeTelephoneNumber] [varchar](25) NULL,
      [ccm_WorkFaxNumber] [varchar](25) NULL,
      [ccm_P4UUsername] [varchar](25) NULL,
      [ccm_P4UPassword] [varchar](25) NOT NULL,
      [ccm_MainContact] [tinyint] NOT NULL   DEFAULT (0),
      [ccm_P4UAdministrator] [tinyint] NOT NULL DEFAULT (0),
      [ccm_EnteredDT] [smalldatetime] NOT NULL,
      [ccm_Active] [tinyint] NOT NULL ,
      [ccm_AuditDT] [datetime] NOT NULL,
      [ccm_AuditESID] [int] NOT NULL,
      [ccm_wpb_SID] [int] NULL,
      [ccm_JobTitle] [varchar](255) NULL,
      [ccm_WorkTelephoneNumber] [varchar](25) NULL,
      [ccm_TempMember] [tinyint] NOT NULL  DEFAULT (0),
      [ccm_InPPScheme] [tinyint] NOT NULL   DEFAULT (0),
      [ccm_PPAdministrator] [tinyint] NOT NULL   DEFAULT (0),
      [ccm_tempperksvalue] [varchar](25) NULL,
      [ccm_CorpName] [varchar](10) NULL,
      [ccm_HomeAddressState] [varchar](20) NULL,
      [ccm_UserPassword] [varbinary](256) NULL,
      [ccm_ChangePassword] [tinyint] NULL,
      [ccm_LastLoggedOnDT] [smalldatetime] NULL,
      [ccm_IsFirstTime] [tinyint] NOT NULL  DEFAULT (1),
      [ccm_MobileNo] [varchar](25) NULL,
      [ccm_UserUsername] [varchar](50) NULL,
      [ccm_CorpSiteAccess] [tinyint] NULL  DEFAULT (0),
      [ccm_InternalAdminNotes] [varchar](255) NULL,
      [ccm_PasswordHint] [varchar](100) NULL,
      [ccm_AuditCCM_SID] [int] NULL,
      [ccm_ExternalID] [varchar](50) NULL,
      [ccm_ImportedByCCM_SID] [int] NULL,
      [ccm_CompanySetupMember] [tinyint] NOT NULL   DEFAULT (0),
      [ccm_CompanySetupExpiryDT] [smalldatetime] NULL,
      [ccm_Gender] [varchar](50) NULL,
      [ccm_BuildingsInsRenewal] [datetime] NULL,
      [ccm_ContentsInsRenewal] [datetime] NULL,
      [ccm_CarInsRenewal] [datetime] NULL,
      [ccm_ExistingRSAMember] [tinyint] NULL,
      [ccm_SelfRegistrationFlag] [tinyint] NOT NULL  DEFAULT (0),
      [ccm_PasswordRetrievalQuestion] [varchar](200) NULL,
      [ccm_PasswordRetrievalAnswer] [varchar](200) NULL,
      [ccm_PasswordRetrievalLastUpdatedDT] [smalldatetime] NULL,
      [ccm_PasswordRetrievalLastResetDT] [smalldatetime] NULL,
      [ccm_PasswordRetrievalLastResetRequestDT] [smalldatetime] NULL,
      [ccm_PasswordRetrievalResetRequestCount] [int] NULL,
      [ccm_CoExternalRef1] [varchar](255) NULL,
      [ccm_CoExternalRef2] [varchar](255) NULL,
      [ccm_CoExternalRef3] [varchar](255) NULL,
      [ccm_CoExternalRef4] [varchar](255) NULL,
      [ccm_CoExternalRef5] [varchar](255) NULL,
      [ccm_JoinCompanyDT] [datetime] NULL,
      [ccm_LeaveCompanyDT] [datetime] NULL,
      [ccm_LeaveCompanyAdvisedDT] [datetime] NULL,
      [ccm_InvalidLoginCount] [int] NOT NULL   DEFAULT (0),
      [ccm_MemberDeniedAccess] [tinyint] NOT NULL  DEFAULT (0),
      [ccm_PasswordChangedDT] [datetime] NULL,
      [ccm_ld_SID] [int] NULL,
      [ccm_NINumber] [varchar](20) NULL,
      [ccm_SelfRegCompanyName] [varchar](100) NULL,
      [rowguid] [uniqueidentifier] ROWGUIDCOL  NOT NULL)
0
Comment
Question by:Richardsoet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 18

Expert Comment

by:ShogunWade
ID: 20409845
Where is your source data coming from ?
0
 
LVL 11

Expert Comment

by:Goodangel Matope
ID: 20409846
where do you want to insert this data from?
0
 

Author Comment

by:Richardsoet
ID: 20409860
I just want to have a sql script that would create a dummy data of 20000 into the the above tables
0
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
LVL 25

Expert Comment

by:imitchie
ID: 20409944
set nocount on
declare @i int set @i = 0
while @i < 20000
begin
insert into tb_CCMemberTest
select ascii(newID()), ascii(newID()), cast(newID() as varchar(50)), cast(newID() as varchar(50)), cast(newID() as varchar(50)), cast(newID() as varchar(50)), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), cast(newID() as varchar(50)), cast(newID() as varchar(50)), cast(newID() as varchar(50)), cast(newID() as varchar(50)), cast(newID() as varchar(50)), cast(newID() as varchar(50)), left(cast(newID() as varchar(50)),10), left(cast(newID() as varchar(50)),25), left(cast(newID() as varchar(50)),25), left(cast(newID() as varchar(50)),25), left(cast(newID() as varchar(50)),25), ascii(newID()), ascii(newID()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), ascii(newID()), cast(newID() as varchar(255)), left(cast(newID() as varchar(50)),25), ascii(newID()), ascii(newID()), ascii(newID()), left(cast(newID() as varchar(50)),25), left(cast(newID() as varchar(50)),10), left(cast(newID() as varchar(50)),20), cast(newid() as varchar(40))+cast(newid() as varchar(40)), ascii(newID()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), left(cast(newID() as varchar(50)),25), cast(newID() as varchar(50)), ascii(newID()), cast(newID() as varchar(255)), cast(newID() as varchar(100)), ascii(newID()), cast(newID() as varchar(50)), ascii(newID()), ascii(newID()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), cast(newID() as varchar(50)), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), ascii(newID()), cast(newID() as varchar(200)), cast(newID() as varchar(200)), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), cast(newID() as varchar(255)), cast(newID() as varchar(255)), cast(newID() as varchar(255)), cast(newID() as varchar(255)), cast(newID() as varchar(255)), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), ascii(newID()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), left(cast(newID() as varchar(50)),20), cast(newID() as varchar(100)), newid()
set @i = @i + 1
end
set nocount off
0
 
LVL 25

Expert Comment

by:imitchie
ID: 20409949
completely RANDOM + absolutely JUNK data
0
 
LVL 25

Expert Comment

by:imitchie
ID: 20409956
sorry, made a mistake with the IDENTITY column, leave that out, so
set nocount on
declare @i int set @i = 0
while @i < 20000
begin
insert into tb_CCMemberTest
selectascii(newID()), cast(newID() as varchar(50)), cast(newID() as varchar(50)), cast(newID() as varchar(50)), cast(newID() as varchar(50)), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), cast(newID() as varchar(50)), cast(newID() as varchar(50)), cast(newID() as varchar(50)), cast(newID() as varchar(50)), cast(newID() as varchar(50)), cast(newID() as varchar(50)), left(cast(newID() as varchar(50)),10), left(cast(newID() as varchar(50)),25), left(cast(newID() as varchar(50)),25), left(cast(newID() as varchar(50)),25), left(cast(newID() as varchar(50)),25), ascii(newID()), ascii(newID()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), ascii(newID()), cast(newID() as varchar(255)), left(cast(newID() as varchar(50)),25), ascii(newID()), ascii(newID()), ascii(newID()), left(cast(newID() as varchar(50)),25), left(cast(newID() as varchar(50)),10), left(cast(newID() as varchar(50)),20), cast(newid() as varchar(40))+cast(newid() as varchar(40)), ascii(newID()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), left(cast(newID() as varchar(50)),25), cast(newID() as varchar(50)), ascii(newID()), cast(newID() as varchar(255)), cast(newID() as varchar(100)), ascii(newID()), cast(newID() as varchar(50)), ascii(newID()), ascii(newID()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), cast(newID() as varchar(50)), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), ascii(newID()), cast(newID() as varchar(200)), cast(newID() as varchar(200)), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), cast(newID() as varchar(255)), cast(newID() as varchar(255)), cast(newID() as varchar(255)), cast(newID() as varchar(255)), cast(newID() as varchar(255)), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), ascii(newID()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), left(cast(newID() as varchar(50)),20), cast(newID() as varchar(100)), newid()
set @i = @i + 1
end
set nocount off

Open in new window

0
 

Author Comment

by:Richardsoet
ID: 20410023
Which out of the two should i used for teh insert , the second on eposted or first one

If the first one posted ,I can not copy and paste please help
0
 

Author Comment

by:Richardsoet
ID: 20410077
Error message :when use the below script

Msg 257, Level 16, State 3, Line 5
Implicit conversion from data type varchar to varbinary is not allowed. Use the CONVERT function to run this query.


set nocount on
declare @i int set @i = 0
while @i < 100
begin
insert into tb_CCMemberTest
select ascii(newID()), cast(newID() as varchar(50)), cast(newID() as varchar(50)), cast(newID() as varchar(50)), cast(newID() as varchar(50)), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), cast(newID() as varchar(50)), cast(newID() as varchar(50)), cast(newID() as varchar(50)), cast(newID() as varchar(50)), cast(newID() as varchar(50)), cast(newID() as varchar(50)), left(cast(newID() as varchar(50)),10), left(cast(newID() as varchar(50)),25), left(cast(newID() as varchar(50)),25), left(cast(newID() as varchar(50)),25), left(cast(newID() as varchar(50)),25), ascii(newID()), ascii(newID()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), ascii(newID()), cast(newID() as varchar(255)), left(cast(newID() as varchar(50)),25), ascii(newID()), ascii(newID()), ascii(newID()), left(cast(newID() as varchar(50)),25), left(cast(newID() as varchar(50)),10), left(cast(newID() as varchar(50)),20), cast(newid() as varchar(40))+cast(newid() as varchar(40)), ascii(newID()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), left(cast(newID() as varchar(50)),25), cast(newID() as varchar(50)), ascii(newID()), cast(newID() as varchar(255)), cast(newID() as varchar(100)), ascii(newID()), cast(newID() as varchar(50)), ascii(newID()), ascii(newID()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), cast(newID() as varchar(50)), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), ascii(newID()), cast(newID() as varchar(200)), cast(newID() as varchar(200)), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), cast(newID() as varchar(255)), cast(newID() as varchar(255)), cast(newID() as varchar(255)), cast(newID() as varchar(255)), cast(newID() as varchar(255)), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), ascii(newID()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), left(cast(newID() as varchar(50)),20), cast(newID() as varchar(100)), newid()
set @i = @i + 1
end
set nocount off
0
 
LVL 25

Expert Comment

by:imitchie
ID: 20410080
The 2nd one, i.e. http:#20409956

Is it too long?
I put line breaks in it
set nocount on
declare @i int set @i = 0
while @i < 20000
begin
insert into tb_CCMemberTest
selectascii(newID()), cast(newID() as varchar(50)), cast(newID() as varchar(50)), cast(newID() as varchar(50)), 
cast(newID() as varchar(50)), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), cast(newID() as varchar(50)), 
cast(newID() as varchar(50)), cast(newID() as varchar(50)), cast(newID() as varchar(50)), cast(newID() as varchar(50)), 
cast(newID() as varchar(50)), left(cast(newID() as varchar(50)),10), left(cast(newID() as varchar(50)),25), 
left(cast(newID() as varchar(50)),25), left(cast(newID() as varchar(50)),25), left(cast(newID() as varchar(50)),25), 
ascii(newID()), ascii(newID()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), 
dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), ascii(newID()), cast(newID() as varchar(255)), 
left(cast(newID() as varchar(50)),25), ascii(newID()), ascii(newID()), ascii(newID()), left(cast(newID() as 
varchar(50)),25), left(cast(newID() as varchar(50)),10), left(cast(newID() as varchar(50)),20), cast(newid() as 
varchar(40))+cast(newid() as varchar(40)), ascii(newID()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), 
ascii(newID()), left(cast(newID() as varchar(50)),25), cast(newID() as varchar(50)), ascii(newID()), cast(newID() as 
varchar(255)), cast(newID() as varchar(100)), ascii(newID()), cast(newID() as varchar(50)), ascii(newID()), ascii(newID()), 
dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), cast(newID() as varchar(50)), 
dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), 
dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), ascii(newID()), cast(newID() as varchar(200)), 
cast(newID() as varchar(200)), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), 
dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), 
ascii(newID()), cast(newID() as varchar(255)), cast(newID() as varchar(255)), cast(newID() as varchar(255)), cast(newID() 
as varchar(255)), cast(newID() as varchar(255)), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), 
dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), 
ascii(newID()), ascii(newID()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), 
left(cast(newID() as varchar(50)),20), cast(newID() as varchar(100)), newid()
 
set @i = @i + 1
end
set nocount off

Open in new window

0
 
LVL 25

Accepted Solution

by:
imitchie earned 250 total points
ID: 20410101
ahh.. 1 change
set nocount on
declare @i int set @i = 0
while @i < 20000
begin
insert into tb_CCMemberTest
selectascii(newID()), cast(newID() as varchar(50)), cast(newID() as varchar(50)), cast(newID() as varchar(50)), 
cast(newID() as varchar(50)), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), cast(newID() as varchar(50)), 
cast(newID() as varchar(50)), cast(newID() as varchar(50)), cast(newID() as varchar(50)), cast(newID() as varchar(50)), 
cast(newID() as varchar(50)), left(cast(newID() as varchar(50)),10), left(cast(newID() as varchar(50)),25), 
left(cast(newID() as varchar(50)),25), left(cast(newID() as varchar(50)),25), left(cast(newID() as varchar(50)),25), 
ascii(newID()), ascii(newID()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), 
dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), ascii(newID()), cast(newID() as varchar(255)), 
left(cast(newID() as varchar(50)),25), ascii(newID()), ascii(newID()), ascii(newID()), left(cast(newID() as 
varchar(50)),25), left(cast(newID() as varchar(50)),10), left(cast(newID() as varchar(50)),20), cast(cast(newid() as 
varchar(40))+cast(newid() as varchar(40)) as varbinary(100)), ascii(newID()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), 
ascii(newID()), left(cast(newID() as varchar(50)),25), cast(newID() as varchar(50)), ascii(newID()), cast(newID() as 
varchar(255)), cast(newID() as varchar(100)), ascii(newID()), cast(newID() as varchar(50)), ascii(newID()), ascii(newID()), 
dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), cast(newID() as varchar(50)), 
dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), 
dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), ascii(newID()), cast(newID() as varchar(200)), 
cast(newID() as varchar(200)), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), 
dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), 
ascii(newID()), cast(newID() as varchar(255)), cast(newID() as varchar(255)), cast(newID() as varchar(255)), cast(newID() 
as varchar(255)), cast(newID() as varchar(255)), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), 
dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), 
ascii(newID()), ascii(newID()), dateadd(day,128-ascii(newid())*16+ascii(newid()),getdate()), ascii(newID()), 
left(cast(newID() as varchar(50)),20), cast(newID() as varchar(100)), newid()
 
set @i = @i + 1
end
set nocount off

Open in new window

0
 

Author Comment

by:Richardsoet
ID: 20410108
Error message when execute the above script please modify

Msg 257, Level 16, State 3, Line 5
Implicit conversion from data type varchar to varbinary is not allowed. Use the CONVERT function to run this query.

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question