To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here

HOME News MS SQL Oracle DB2 Access MySQL PHP Scripts Books Links DBA Talk


Go Back   Database Journal Forums > Related Sites > SQL Course

SQL Course SQL Course > Ask questions about the lessons on SQL Course 1 and 2. If you have problems > with the interface, please post in the Feedback forum

Reply Post New Thread
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 01-18-2003, 01:59 AM
rsunitha rsunitha is offline
Junior Member
 
Join Date: Jan 2003
Location: India
Posts: 2
Inserting over a lakh of records

I have a table with a column userid. There are around 1 lakh userids.
Similarly, Iam having a table UserData where I have to insert for each userid.
The data is sent thru asp gae and it take around 45 minutes to complete and mostly the system hangs. Please help

--Sunitha





CREATE Procedure InsertMailstoUserData
@data1 nvarchar(256),
@data2 nvarchar(256),
@data3 nvarchar(256),
@data4 smallint,
@data5 ntext = null,
@data6 int


AS

set nocount on

Begin

DECLARE @userid
DECLARE @Count_1 DECIMAL
SET @Count_1=1

DECLARE userid CURSOR FOR SELECT userid FROM User

OPEN userid
-- there are over lakh of userid
FETCH NEXT FROM userid INTO @userid

WHILE @@FETCH_STATUS = 0
BEGIN



DECLARE @TransName varchar(30)
SET @TransName= 'NEWINSERT'
BEGIN TRANSACTION @TransName
-- for each userid insert is to be done
Insert into UserData(userid,data1,data2,data3,data4,data5,data 6) values (@userid,@data1,@data2,@data3,@data4,@data5,@data6 )

IF (@@error <> 0)
BEGIN
ROLLBACK TRANSACTION @TransName
RAISERROR ('Cannot insert a record in userdata.', 16, 1)
return
END

COMMIT TRANSACTION @TransName

SET @Count_1 = @Count_1 + 1

FETCH NEXT FROM userid INTO @userid
END

CLOSE pin_cursor
DEALLOCATE pin_cursor


End
GO
Reply With Quote
  #2  
Old 01-20-2003, 07:58 AM
skhanal skhanal is offline
Experts
 
Join Date: Nov 2002
Location: New Jersey, USA
Posts: 3,369
It seems you are trying to insert the same data for all users in User table, if that is correct, avoid cursor by using one INSERT statement.



CREATE Procedure InsertMailstoUserData
@data1 nvarchar(256),
@data2 nvarchar(256),
@data3 nvarchar(256),
@data4 smallint,
@data5 ntext = null,
@data6 int


AS

set nocount on

Begin
DECLARE @TransName varchar(30)
SET @TransName= 'NEWINSERT'
BEGIN TRANSACTION @TransName
-- for each userid insert is to be done
Insert into UserData(userid,data1,data2,data3,data4,data5,data
6)
select userid,@data1,@data2,@data3,@data4,@data5,@data6
from user


IF (@@error <> 0)
BEGIN
ROLLBACK TRANSACTION @TransName
RAISERROR ('Cannot insert a record in userdata.', 16, 1)
return
END

COMMIT TRANSACTION @TransName
End
__________________
http://gotodba.com
Reply With Quote
  #3  
Old 01-22-2003, 12:40 AM
rsunitha rsunitha is offline
Junior Member
 
Join Date: Jan 2003
Location: India
Posts: 2
Basically Iam taking a userid from a table and then inserting ame data for that userid.
Reply With Quote
Reply Post New Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 04:39 AM.


DatabaseJournal Recent Articles


 » Preparing To Upgrade Access Tables to SQL ...

 » Microsoft Windows PowerShell and SQL Serve...

 » New MySQL Enterprise with Query Analyzer B...

 » Quest Software Strengthens Committment to ...

 » Oracle Unveils New Event-Driven Middleware...

Search Database Journal:
 





Acceptable Use Policy

JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers

Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.