Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
How to Insert 5000 thousand records in 1 table using SQL, and the column emailId should not repeat it should be always new emailId.

Thanks in Advance,

Priya.
Posted
Comments
Uday P.Singh 11-Apr-12 9:51am    
not clear! do you want it to insert from backend? and do you have all the email ids? or what
Priyadarshini.Thokala 11-Apr-12 9:54am    
Yes wanna insert 5000 records from backend, and emailid should not be the same for example in 1st row priya@gmail.com then in second priya1@gmail.com like that..

Try:
SQL
DECLARE @count INT
SET @count = 1
WHILE (@count <= 5000)
BEGIN
   INSERT INTO myTable(Email) VALUES ('priya'+ CONVERT(nvarchar, @count) + '@gmail.com')
   SET @count = (@count + 1)
END
 
Share this answer
 
Comments
Priyadarshini.Thokala 12-Apr-12 5:22am    
Thank you.
SQL
DECLARE @UserId INT
SET @count = 1
WHILE (@count <= 5000)
BEGIN
   INSERT INTO tblUser1(EmailID, UserTypeID,FirstName,LastName,PhoneNumber,UniversityID,RegisterDate,ActivationDate,Status,Password,IsAV)
                VALUES ('priyanka'+ CONVERT(nvarchar, @count) + '@gmail.com',5,'priya','darshini','5468927689',10,'2012-04-12 02:09:59.040',null,1,'Test123',1)
   SET @count = (@count + 1)
   SELECT @UserId = @@IDENTITY

   INSERT INTO tblAddress1(UserID,AddressLine1,AddressLine2,City,StateID,ZipCode) Values(@UserId,'test',NULL,'Hyd',34,50040)

END
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900