1

Question is pretty simple but just in case I'll explain it.

Is there a way to drop ALL the the assemblies in a Microsoft SQL Server?

I know that there's a way to delete them on at a time using

DROP ASSEMBLY ['assembly_name']; 
4
  • Nope, will have to cycle through available ones and go one by one. Commented May 9, 2018 at 15:02
  • Thanks! But in that case, is there a way to list them? Cause I'm working in a legacy DB. Commented May 9, 2018 at 15:03
  • Try the system table sys.assemblies, I think it's available from version 2008 onwards. This table is scoped by database tho. Commented May 9, 2018 at 15:06
  • Thanks! That one worked. Commented May 9, 2018 at 15:10

2 Answers 2

2

I never worked with assemblies but they should be in a structure within sys like everything else on SQL SERVER. I usually build massive commands by using a code similar to this one. Please note that within my environment all the tables related to assemblies are empty so I cannot say if the table and column I picked up with the select are correct, you will need to figure out on yourself.

declare @cmd NVARCHAR(MAX) set @cmd='' select @cmd=@cmd+ 'DROP ASSEMBLY [''' + am.assembly_class +'''];'+CHAR(13) from sys.assembly_modules am PRINT @cmd --Copy and paste the Messages content from SQL Server Management studio to a new query or uncomment the row below to execute --EXEC sp_executesql @cmd 
Sign up to request clarification or add additional context in comments.

Comments

0

Note: this code does not allow for dependencies between assemblies, so you may have to run it 2-3 times before all assemblies are dropped.

/* Drop all assemblies */ DECLARE @SQL VARCHAR(MAX) DECLARE @name VARCHAR(128) DECLARE cur CURSOR FAST_FORWARD READ_ONLY FOR SELECT name FROM sys.assemblies WHERE is_user_defined=1 OPEN cur FETCH NEXT FROM cur INTO @name WHILE @@FETCH_STATUS = 0 BEGIN SELECT @SQL = 'DROP ASSEMBLY ' + RTRIM(@name) PRINT @SQL EXEC (@SQL) FETCH NEXT FROM cur INTO @name END CLOSE cur DEALLOCATE cur 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.