Skip to content
Advertisement

Did this SQL update statement delete records? [closed]

I ran an update statement like this, last night.

Update a SET a.COUNTRY = c.[ISO (2)] -- Select c.*,b.[country name]
FROM Table_V2 a
JOIN [SourceDATA].[dbo].masterdata b 
ON a.Doc_Number = REPLACE(STR(TRY_CAST(b.[order number] AS INT),10),' ','0') 
AND a.SHIP_TO = REPLACE(STR(TRY_CAST(b.[ship to number] AS INT),10),' ','0') 
AND a.SOLD_TO = REPLACE(STR(TRY_CAST(b.[sold to number] AS INT),10),' ','0') 
AND a.SKU = b.[sku number]
LEFT JOIN [CountryCodes] AS c 
On 
CASE WHEN UPPER(b.[country name]) in (SELECT COUNTRY FROM CountryCodes) THEN UPPER(b.[country name])
WHEN UPPER(b.[country name]) = 'SOUTH KOREA' THEN UPPER('Korea, South')
WHEN UPPER(b.[country name]) = 'NORTH KOREA' THEN UPPER('Korea, North')
WHEN UPPER(b.[country name]) like '%PORTUGAL%' THEN UPPER('Portugal')
WHEN UPPER(b.[country name]) like '%HONG KONG%' THEN UPPER('Hong Kong (China)') 
END = UPPER(c.Country)
WHERE a.COUNTRY is null  

where it is joining local data Table_V2 with data on another server/database (on SourceDATA server) which is aliased as “b”, but only actually updating the local table, a…(I hope).

Coming back this morning, that master data table on the other server is totally empty, when normally there’s at least a million records. I know that some refreshes happen with data on [today], but it’s been empty for many hours and I’m getting worried that I may have accidentally deleted the data with my update statement. I’m not aware of any refreshes that delete all the data first although I supposed it’s possible. Is it possible that I deleted the data by accident?

My understanding – which I was really certain was correct – is that my update statement won’t touch anything from b; it only looks at it. and updates a. I’m just so worried now hoping it’s all a coicidence because I’ve never seen b empty, and I don’t think the refreshes normally take very long. Hopefully am I missing something? Could this have been me?

Advertisement

Answer

No need to worry. Your are only changing the data in table Table_V2. You can check if there is a trigger on it that potentially can apply additional data manipulation.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement