Help with Delete query in SQL.

I have a SQL database that populates tables on my local machine.  I then upload this data to a SQL database that is being hosted with Microsoft Azure.  Typically when I am done uploading the data to Azure, I delete it locally.  I do this for backups and to give my clients access to it.

I have one local table that I am having a hard time deleting data from.  I have 4 columns that also constitute the key.   I have a screenshot below.  These four columns will always produce a unique row, however any one of these columns by themselves will not.

Below is an example of data that I want to delete locally.  These are database records that are locally stored and in Azure.  Since they are in Azure, I want to delete them locally.

select c.[statusId], c.[classifierName], c.[className], c.[classValue] 
FROM [dbo].[classifications] c
Inner join [AzureSQL].[MyDb].[dbo].[classifications] ac on 
	c.statusId = ac.statusId 
	and c.classifierName = ac.classifierName
	and c.className = ac.className
	and c.classValue = ac.classVale

Open in new window


How can I update this query to delete my local records?

My local table is [dbo].[classifications]

While my Azure table is [AzureSQL].[MyDb].[dbo].[classifications]

Also, Azure is setup as a linked server.  Any help would be greatly appreciated.
screenshot.jpg
rye004Asked:
Who is Participating?
 
ste5anSenior DeveloperCommented:
Instead of SELECT columnlist FROM use DELETE aliasname FROM. Thus this should work:

DELETE c
FROM [dbo].[classifications] c
Inner join [AzureSQL].[MyDb].[dbo].[classifications] ac on 
	c.statusId = ac.statusId 
	and c.classifierName = ac.classifierName
	and c.className = ac.className
	and c.classValue = ac.classVale

Open in new window


And as always: make backups first, before testing :)
0
 
rye004Author Commented:
I tried that and I get the following:

Msg 102, Level 15, State 1, Line 2
Incorrect syntax near 'c'.

Thanks for your help!
0
 
rye004Author Commented:
Actually, it did work!  I made a typo.  Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.