Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

Delete data in loop using values available in the table without PrimaryKey & ForeignKey violation errors

$
0
0
DROP TABLE #Temp

CREATE TABLE #Temp (ID int, ColumnName varchar(100), ValueToBeDeleted varchar(100), TableName varchar(100),ServerName varchar(100))
INSERT INTO #Temp
SELECT 1, 'CustomerID'	, '123'	, 'Database.dbo.Customer', 'tprd1' UNION ALL
SELECT 2, 'CustomerID'	, '142'	, 'Database.dbo.Customer', 'tprd1' UNION ALL
SELECT 3, 'OrderID'		, 'OR124'	, 'Database.dbo.Orders'	, 'tprd1' UNION ALL
SELECT 4, 'ProductID'	, '65655'	, 'Database.dbo.Product', 'tprd1' 

--SELECT * FROM #Temp t

I have kind of above table where i have values to be deleted from the sources. For example sake i am posting 4 rows here but there are millions of rows that i have to work on.  This table keeps on growing.
Within SSIS i need to loop through all the rows and construct a SQL like below and EXECUTE on the respective Server and DB found in the table.
But, am getting PrimaryKey foreign key violation errors WHILE running the package. How do we bypass Pkey and Fkeys to DELETE the data ? Or is there any way i can DELETE data without dropping the PrimaryKEy or ForeignKeys ? 

DELETE FROM Database.dbo.Customer WHERE CustomerID =123 

Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>