March 30, 2012 at 12:06 pm
I performed an initial load of data into hundered of tables.
I did not create the tables, if I had, I would not have this problem
How can I delete an Incremental Load of Data without Identify Column or DateTime Stamp, Row_Number?
The tables need to be altered and columns added with defaults but what if I did not do this?
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
March 30, 2012 at 12:22 pm
Only things I can think of off the top of my head.
One, do you have a backup prior to the load you want to delete?
Two, can you use the input for the load to identify the data you need to delete?
Three, if all else fails, can you recreate everything from scratch?
Sorry if all I can give you right now is a bunch of questions.
March 30, 2012 at 12:30 pm
If there's something that uniquely identifies the rows (such as a PK or other candidate column), load the incremental data into a staging table, delete all the rows in the target table that are contained in the staging table using a simple join on the "unique" column(s), and then insert the incremental load.
--Jeff Moden
Change is inevitable... Change for the better is not.
April 1, 2012 at 8:10 pm
This might also work for you:
CREATE TABLE #abc (ID INT, val VARCHAR(10), other CHAR(4))
CREATE TABLE #load (ID INT, val VARCHAR(10))
INSERT #abc (ID, val)
SELECT 1 AS ID, 'ABC' as val UNION ALL SELECT 2, 'DEF'
UNION ALL SELECT 3, 'EFG' UNION ALL SELECT 4, 'HIJ' UNION ALL SELECT 5, 'KLM'
ALTER TABLE #abc
ADD CONSTRAINT def_other DEFAULT 'ABC' FOR other
SELECT * FROM #abc
INSERT #load (ID, val)
SELECT 3 AS ID, 'EFG' AS val UNION ALL SELECT 4, 'HIJ' UNION ALL SELECT 5, 'KLM'
UPDATE a SET other = DEFAULT
FROM #abc a INNER JOIN #load l ON a.ID = l.ID
SELECT * FROM #abc
DROP TABLE #abc
DROP TABLE #load
Users UPDATE only compared to Jeff's suggestion of DELETE/INSERT.
My thought question: Have you ever been told that your query runs too fast?
My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
Since random numbers are too important to be left to chance, let's generate some![/url]
Learn to understand recursive CTEs by example.[/url]
[url url=http://www.sqlservercentral.com/articles/St
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply