Skip to content

Latest commit

 

History

History
79 lines (63 loc) · 3.71 KB

dropping-an-assembly.md

File metadata and controls

79 lines (63 loc) · 3.71 KB
title description author ms.author ms.date ms.service ms.subservice ms.topic helpviewer_keywords
Drop an Assembly
You can delete, or drop, an assembly in SQL Server when it's no longer needed. Use DROP ASSEMBLY to remove an assembly and its associated files.
rwestMSFT
randolphwest
12/27/2024
sql
clr
reference
removing assemblies
DROP ASSEMBLY statement
assemblies [CLR integration], removing
dropping assemblies

Drop an assembly

[!INCLUDE SQL Server]

Assemblies that are registered in [!INCLUDE ssNoVersion] 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 doesn't 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's 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.

Remove 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.

Find UDT dependencies

You must first drop all dependent objects, and then execute the DROP TYPE statement. The following [!INCLUDE tsql] query locates all of the columns and parameters that use a UDT in the [!INCLUDE sssampledbobject-md] database.

USE Adventureworks2022;
GO

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
     INNER JOIN sys.objects AS o
         ON o.object_id = c.object_id
     INNER JOIN sys.assembly_types AS at
         ON at.user_type_id = c.user_type_id;

Related content