jon24422531
Technical User
Hi guys
I always get a good response here, so I am confident of an answer to this:
For historic reasons our company creates a new database for each new customer. These consist of several identical tables, two of which store all the pertinent information for that customer. Some of these tables are large, some not so, but they are all identical in structure.
Now we would like to copy all the data from each DB (total around 13,000,000 records) to another server on one large DB each evening. Our DBA (who is away this week) always approaches these issues in the same way by opening QA and typing "DECLARE CURS CURSOR FOR SELECT...."
We run this from the target server:
This often fails and sends me this Email:
JOB RUN: 'MAINDB : All Custs STORAGE' was run on 20/03/2006 at 18:30:01
DURATION: 12 hours, 39 minutes, 24 seconds
STATUS: Failed
MESSAGES: The job failed. The Job was invoked by Schedule 1 (Mon - Sat, 18:30). The last step to run was step 2 (Cursively INSERT From Customer DB's).
Step 1 incidentally is to truncate the table.
So my question is, is there a better way to run this rather than using a cursor?
Jon
I always get a good response here, so I am confident of an answer to this:
For historic reasons our company creates a new database for each new customer. These consist of several identical tables, two of which store all the pertinent information for that customer. Some of these tables are large, some not so, but they are all identical in structure.
Now we would like to copy all the data from each DB (total around 13,000,000 records) to another server on one large DB each evening. Our DBA (who is away this week) always approaches these issues in the same way by opening QA and typing "DECLARE CURS CURSOR FOR SELECT...."
We run this from the target server:
Code:
DECLARE @Database VARCHAR(100), @SQL VARCHAR(1000)
DECLARE CURS CURSOR FOR SELECT C.CustID FROM SERVER4.MAINDB.dbo.CUSTOMER C JOIN SERVER4.master.dbo.sysdatabases D ON C.CustID=D.name ORDER BY C.CustID
OPEN CURS
FETCH CURS INTO @Database
WHILE @@FETCH_STATUS=0
BEGIN
SET @SQL='INSERT INTO ALLCUSTS..STORAGE SELECT '''+@Database+''', * FROM SERVER4.'+@Database+'.dbo.STORAGE'
EXEC(@SQL)
FETCH CURS INTO @Database
END
CLOSE CURS
DEALLOCATE CURS
JOB RUN: 'MAINDB : All Custs STORAGE' was run on 20/03/2006 at 18:30:01
DURATION: 12 hours, 39 minutes, 24 seconds
STATUS: Failed
MESSAGES: The job failed. The Job was invoked by Schedule 1 (Mon - Sat, 18:30). The last step to run was step 2 (Cursively INSERT From Customer DB's).
Step 1 incidentally is to truncate the table.
So my question is, is there a better way to run this rather than using a cursor?
Jon