# Replication SQL SERVER

```sql
-- Xoa bo tat ca cac Replication dang co tren @dbname
USE master
EXEC sp_removedbreplication @dbname='DTECH'
GO
-- Xoa sub
sp_dropsubscription @subscriber='smxprepl'
--Xoa pub
sp_droppublication 'smxppublisher'

-- Thong tin cac Pub tren SQL
Use distribution
select publisher_database_id, publisher_id, publisher_db,
publication_id,article_id, subscriber_id,
subscriber_db, status
from MSsubscriptions
---- End ------------------------

-- Xoa loi cac log_reader
-- Xem thong tin tu database: msdb,distribution
select * from msdb..MSdistpublishers
select * from distribution..MSpublisher_databases
select * from distribution..MSpublications
select * from distribution..MSarticles
select * from distribution..MSsubscriptions
-- Xoa cac table day di tu database pub
delete from distribution..MSarticles where publisher_db = 'DTECH'
--Xoa Sub
delete from distribution..MSsubscriptions where publisher_db = 'DTECH'

--- Xem thong tin cac Job tren he thong: xem Job_name,Job_ID de  dung delete job
Use msdb
SELECT *
FROM msdb.dbo.sysjobs 
---
Use msdb
DECLARE @JobName varchar(max)
SELECT @JobName = [name] 
FROM msdb.dbo.sysjobs WHERE job_id = cast(0xCDD5865A3C51D911936200508BAD07B9 AS uniqueidentifier)
EXECUTE
msdb..sp_help_job @job_name = @JobNameEXECUTE
msdb..sp_help_jobstep @job_name = @JobName

-- Xoa job
EXECUTE msdb.dbo.sp_delete_job @job_name='WIN-SKXUFJP6AYH-EFFTECA-DM_TAXTC-35'
EXECUTE msdb.dbo.sp_delete_job @job_id='C193FC11-29E1-44E3-BEAC-85E568A26920'


---Go bo Database DISTRIBUTION 
use master 
go 
alter database distribution set offline; 
drop database distribution;

---- Go bo Distribution khoi su quan ly cua Manager Studio
exec sp_dropdistributiondb @database = N'distribution'
GO
exec sp_dropdistributor @no_checks = 1, @ignore_distributor = 1
GO

----

-- Disable publishing and distribution.
DECLARE @distributionDB AS sysname;
--DECLARE @publisher AS sysname;
DECLARE @publicationDB as sysname;
SET @distributionDB = N'distribution';
--SET @publisher = $(DistPubServer);
SET @publicationDB = N'DTECH';

-- Disable the publication database.
USE EFFVTB
EXEC sp_removedbreplication @publicationDB;

-- Remove the registration of the local Publisher at the Distributor.
USE master
--EXEC sp_dropdistpublisher @publisher;

-- Delete the distribution database.
EXEC sp_dropdistributiondb @distributionDB;

-- Remove the local server as a Distributor.
EXEC sp_dropdistributor;
GO

---------------------

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kythuat.dtechvn.com/sql-server/replication-sql-server.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
