| title | sp_dropdistributiondb (Transact-SQL) | ||
|---|---|---|---|
| description | Drops a distribution database and files used by it if they aren't used by another database. This stored procedure runs at the Distributor on any database. | ||
| author | markingmyname | ||
| ms.author | maghan | ||
| ms.reviewer | randolphwest | ||
| ms.date | 06/23/2025 | ||
| ms.service | sql | ||
| ms.subservice | replication | ||
| ms.topic | reference | ||
| f1_keywords |
|
||
| helpviewer_keywords |
|
||
| dev_langs |
|
[!INCLUDE SQL Server SQL MI]
Drops a distribution database. Drops the physical files used by the database if they aren't used by another database. This stored procedure is executed at the Distributor on any database.
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions
sp_dropdistributiondb
[ @database = ] N'database'
[ , [ @former_ag_secondary = ] former_ag_secondary ]
[ ; ]
The database to drop. @database is sysname, with no default.
Specifies whether this node was previously part of an availability group for the distribution database. @former_ag_secondary is int, with a default of 0.
0 (success) or 1 (failure).
sp_dropdistributiondb is used in all types of replication.
This stored procedure must be executed before dropping the Distributor by executing sp_dropdistributor.
sp_dropdistributiondb also removes a Queue Reader Agent job for the distribution database, if one exists.
To disable distribution, the distribution database must be online. If a database snapshot exists for the distribution database, it must be dropped before disabling distribution. A database snapshot is a read-only offline copy of a database, and isn't related to a replication snapshot. For more information, see Database snapshots (SQL Server).
:::code language="sql" source="../replication/codesnippet/tsql/sp-dropdistributiondb-tr_1.sql":::
Only members of the sysadmin fixed server role can execute sp_dropdistributiondb.