Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Finding Deleted Records. Use Stored Procs?

Author  Topic 

DavidChel
Constraint Violating Yak Guru

474 Posts

Posted - 2011-06-18 : 15:06:54
I'm working on a Data Warehouse implementation using SSIS 2008. The source system is in SQL 2000.

The code to find deleted records and insert them into a deleted records table is as follows:

INSERT INTO MDA.DeleteRecords (TableID, RecordID)
SELECT Deltd.TableID TablID, NUM.NumberList
FROM MDA.Numbers NUM
LEFT OUTER JOIN dbo.slcdpm SLC
ON NUM.NumberList = SLC.identity_column
LEFT OUTER JOIN (SELECT DR.TableID, DR.RecordID, DR.DateDeleted
FROM MDA.DeleteTables DT
INNER JOIN
MDA.DeleteRecords DR
ON DR.TableID = DT.TableID
WHERE DT.TableName = 'slcdpm') Deltd
ON Deltd.RecordID = NUM.NumberList
WHERE SLC.identity_column IS NULL
AND NUM.NumberList <= IDENT_CURRENT ('slcdpm')
AND Deltd.TableID IS NULL

Basically I am using Left Outer Join (where null) twice to find records that exist in a numbers table, but don't exist in the source table, nor are already listed as deleted in the DeleteRecords table.

I'd love to call this whole thing from one stored procedure and just pass in the source table name. However, I know you shouldn't do that and no performance benefit will be gained by using a SP to run dynamic SQL.

I have approximately 300 tables which will have to be checked this way.

Should I actually create 300 separate stored procedures, one for each table?

Use SQL that is dynamically generated in SSIS to pull newly deleted records per source table?

I'd love to use delete triggers, but that won't be allowed on this project.

Any suggestions?

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-06-18 : 17:08:49
I would have a stored procedure for each table but generate the stored procedure from an SP.
Would also execute the code from the sp but you could copy the output to a query window to execute.
It's quite easy to build.
I populate a staging table and do all type 1 and type 2 dimension processing like this.

would also log the start and aend and number of rows affects for performance and failure troubleshooting.
==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -