Dropping an Assembly
New: 5 December 2005
Assemblies that have been registered in Microsoft SQL Server using the CREATE ASSEMBLY statement can be deleted, or dropped, when the functionality they provide is no longer needed. Dropping an assembly removes the assembly and all of its associated files, such as debug files, from the database. To drop an assembly, use the DROP ASSEMBLY statement with the following syntax:
DROP ASSEMBLY MyDotNETAssembly
DROP ASSEMBLY does not interfere with any code referencing the assembly that is currently running, but after DROP ASSEMBLY executes, any attempts to invoke the assembly code fail.
DROP ASSEMBLY returns an error if the assembly is referenced by another assembly that exists in the database, or if it is used by common language runtime (CLR) functions, procedures, triggers, user-defined types (UDTs), or user-defined aggregates (UDAs) in the current database. First use the DROP AGGREGATE, DROP FUNCTION, DROP PROCEDURE, DROP TRIGGER, and DROP TYPE statements to delete any managed database objects contained in the assembly.
Removing a UDT from the Database
The DROP TYPE statement removes a UDT from the current database. Once a UDT is dropped, you can use the DROP ASSEMBLY statement to drop the assembly from the database.
The DROP TYPE statement fails if objects depend on the UDT, as in the following situations:
- Tables in the database that contain columns defined using the UDT.
- Functions, stored procedures, or triggers that use variables or parameters of the UDT, created in the database with the WITH SCHEMABINDING clause.
Finding UDT Dependencies
You must first drop all dependent objects, and then execute the DROP TYPE statement. The following Transact-SQL query locates all of the columns and parameters that use a UDT in the AdventureWorks database.
USE Adventureworks;
SELECT o.name AS major_name, o.type_desc AS major_type_desc
, c.name AS minor_name, c.type_desc AS minor_type_desc
, at.assembly_class
FROM (
SELECT object_id, name, user_type_id, 'SQL_COLUMN' AS type_desc
FROM sys.columns
UNION ALL
SELECT object_id, name, user_type_id, 'SQL_PROCEDURE_PARAMETER'
FROM sys.parameters
) AS c
JOIN sys.objects AS o
ON o.object_id = c.object_id
JOIN sys.assembly_types AS at
ON at.user_type_id = c.user_type_id;
See Also
Concepts
Managing CLR Integration Assemblies
Altering an Assembly
Creating an Assembly
Other Resources
DROP AGGREGATE (Transact-SQL)
DROP FUNCTION (Transact-SQL)
DROP PROCEDURE (Transact-SQL)
DROP TRIGGER (Transact-SQL)
DROP TYPE (Transact-SQL)