Generate DROP statements for all extended properties
Posted
by jamiet
on SQL Blog
See other posts from SQL Blog
or by jamiet
Published on Sun, 25 Mar 2012 21:35:29 GMT
Indexed on
2012/03/25
23:37 UTC
Read the original article
Hit count: 504
Extended Properties
|SQL Server
This evening I have been attempting to migrate an existing on-premise database to SQL Azure using the wizard that is built-in to SQL Server Management Studio (SSMS). When I did so I received the following error:
The following objects are not supported =
[MS_Description] = Extended Property
Evidently databases containing extended properties can not be migrated using this particular wizard so I set about removing all of the extended properties – unfortunately there were over a thousand of them so I needed a better way than simply deleting each and every one of them manually. I found a couple of resources online that went some way toward this:
- Drop all extended properties in a MSSQL database by Angelo Hongens
- Modifying and deleting extended properties by Adam Aspin
Unfortunately neither provided a script that exactly suited my needs. Angelo’s covered extended properties on tables and columns however I had other objects that had extended properties on them. Adam’s looked more complete but when I ran it I got an error:
Msg 468, Level 16, State 9, Line 78
Cannot resolve the collation conflict between "Latin1_General_100_CS_AS" and "Latin1_General_CI_AS" in the equal to operation.
So, both great resources but I wasn’t able to use either on their own to get rid of all of my extended properties. Hence, I combined the excellent work that Angelo and Adam had provided in order to manufacture my own script which did successfully manage to generate calls to sp_dropextendedproperty for all of my extended properties. If you think you might be able to make use of such a script then feel free to download it from https://skydrive.live.com/redir.aspx?cid=550f681dad532637&resid=550F681DAD532637!16707&parid=550F681DAD532637!16706&authkey=!APxPIQCatzC7BQ8. This script will remove extended properties on tables, columns, check constraints, default constraints, views, sprocs, foreign keys, primary keys, table triggers, UDF parameters, sproc parameters, databases, schemas, database files and filegroups. If you have any object types with extended properties on them that are not in that list then consult Adam’s aforementioned article – it should prove very useful.
I repeat here the message that I have placed at the top of the script:
/*
This script will generate calls to sp_dropextendedproperty for every extended property that exists in your database.
Actually, a caveat: I don't promise that it will catch each and every extended property that exists, but I'm confident it will catch most of them!It is based on this:
http://blog.hongens.nl/2010/02/25/drop-all-extended-properties-in-a-mssql-database/
by Angelo Hongens.Also had lots of help from this:
http://www.sqlservercentral.com/articles/Metadata/72609/
by Adam AspinAdam actually provides a script at that link to do something very similar but when I ran it I got an error:
Msg 468, Level 16, State 9, Line 78
Cannot resolve the collation conflict between "Latin1_General_100_CS_AS" and "Latin1_General_CI_AS" in the equal to operation.So I put together this version instead.
Use at your own risk.
Jamie Thomson
2012-03-25
*/
Hope this is useful to someone!
© SQL Blog or respective owner