게시 삭제

적용 대상:SQL ServerAzure SQL Managed Instance

이 항목에서는 SQL Server Management Studio, Transact-SQL 또는 RMO(복제 관리 개체)를 사용하여 SQL Server에서 게시를 삭제하는 방법을 설명합니다.

항목 내용

SQL Server Management Studio 사용

SQL Server Management Studio의 로컬 게시 폴더에서 게시를 삭제합니다 .

게시를 삭제하려면

  1. Management Studio에서 게시자에 커넥트 서버 노드를 확장합니다.

  2. 복제 폴더를 확장한 다음 로컬 게시 폴더를 확장합니다.

  3. 삭제할 게시를 마우스 오른쪽 단추로 클릭한 다음 삭제를 클릭합니다.

Transact-SQL 사용

게시는 복제본(replica)tion 저장 프로시저를 사용하여 프로그래밍 방식으로 삭제할 수 있습니다. 사용하는 저장 프로시저는 삭제되는 게시의 유형에 따라 달라집니다.

참고 항목

게시를 삭제해도 게시 데이터베이스 또는 구독 데이터베이스에서 해당 개체에서 게시된 개체가 제거되지는 않습니다. DROP <object> 필요한 경우 명령을 사용하여 이러한 개체를 수동으로 제거합니다.

스냅샷 또는 트랜잭션 게시를 삭제하려면

  1. 다음 중 하나를 수행합니다.

    • 단일 게시를 삭제하려면 게시 데이터베이스의 게시자에서 sp_droppublication 실행합니다.

    • 모든 게시를 삭제하고 게시된 데이터베이스에서 모든 복제 개체를 제거하려면 게시자에서 sp_removedbreplication 을 실행합니다. @type tran 값을 지정합니다. (선택 사항) 배포자에 액세스할 수 없거나 데이터베이스의 상태 의심되거나 오프라인인 경우 @force 값 1지정합니다. (선택 사항) 게시 데이터베이스에서 sp_removedb복제본(replica) 실행되지 않는 경우 @dbname 데이터베이스의 이름을 지정합니다.

      참고 항목

      @force 값을 1로 지정하면 데이터베이스에 복제본(replica) 관련 게시 개체가 남을 수 있습니다.

  2. (선택 사항) 이 데이터베이스에 다른 게시가 없는 경우 sp_복제본(replica)tiondboption(Transact-SQL)을 실행하여 스냅샷 또는 트랜잭션 복제본(replica) 사용하여 현재 데이터베이스의 게시를 사용하지 않도록 설정합니다.

  3. (선택 사항) 구독 데이터베이스의 구독자에서 sp_subscription_클린up을 실행하여 구독 데이터베이스에서 다시 기본복제본(replica)tion 메타데이터를 제거합니다.

병합 게시를 삭제하려면

  1. 다음 중 하나를 수행합니다.

    • 단일 게시를 삭제하려면 게시 데이터베이스의 게시자에서 sp_dropmergepublication(Transact-SQL)를 실행합니다.

    • 모든 게시를 삭제하고 게시된 데이터베이스에서 모든 복제 개체를 제거하려면 게시자에서 sp_removedbreplication 을 실행합니다. @type 병합값을 지정합니다. (선택 사항) 배포자에 액세스할 수 없거나 데이터베이스의 상태 의심되거나 오프라인인 경우 @force 값 1지정합니다. (선택 사항) 게시 데이터베이스에서 sp_removedb복제본(replica) 실행되지 않는 경우 @dbname 데이터베이스의 이름을 지정합니다.

      참고 항목

      @force 값을 1로 지정하면 데이터베이스에 복제본(replica) 관련 게시 개체가 남을 수 있습니다.

  2. (선택 사항) 이 데이터베이스에 다른 게시가 없는 경우 sp_복제본(replica)tiondboption(Transact-SQL)을 실행하여 병합 복제본(replica)tion을 사용하여 현재 데이터베이스의 게시를 사용하지 않도록 설정합니다.

  3. (선택 사항) 구독 데이터베이스의 구독자에서 sp_mergesubscription_클린up(Transact-SQL)을 실행하여 구독 데이터베이스에서 다시 기본복제본(replica)tion 메타데이터를 제거합니다.

예제(Transact-SQL)

이 예제에서는 트랜잭션 게시를 제거하고 데이터베이스에 대한 트랜잭션 게시를 사용하지 않도록 설정하는 방법을 보여줍니다. 이 예제에서는 모든 구독이 이전에 제거되었다고 가정합니다. 자세한 내용은 끌어오기 구독 삭제 또는 밀어넣기 구독 삭제를 참조하세요.

DECLARE @publicationDB AS sysname;
DECLARE @publication AS sysname;
SET @publicationDB = N'AdventureWorks'; 
SET @publication = N'AdvWorksProductTran'; 

-- Remove a transactional publication.
USE [AdventureWorks2022]
EXEC sp_droppublication @publication = @publication;

-- Remove replication objects from the database.
USE [master]
EXEC sp_replicationdboption 
  @dbname = @publicationDB, 
  @optname = N'publish', 
  @value = N'false';
GO

이 예제에서는 병합 게시를 제거하고 데이터베이스에 대한 병합 게시를 사용하지 않도록 설정하는 방법을 보여줍니다. 이 예제에서는 모든 구독이 이전에 제거되었다고 가정합니다. 자세한 내용은 끌어오기 구독 삭제 또는 밀어넣기 구독 삭제를 참조하세요.

DECLARE @publication AS sysname
DECLARE @publicationDB    AS sysname
SET @publication = N'AdvWorksSalesOrdersMerge' 
SET @publicationDB = N'AdventureWorks'

-- Remove the merge publication.
USE [AdventureWorks]
EXEC sp_dropmergepublication @publication = @publication;

-- Remove replication objects from the database.
USE master
EXEC sp_replicationdboption 
  @dbname = @publicationDB, 
  @optname = N'merge publish', 
  @value = N'false'
GO

RMO(복제 관리 개체) 사용

RMO(복제 관리 개체)를 사용하여 프로그래밍 방식으로 게시를 삭제할 수 있습니다. 게시를 제거하는 데 사용하는 RMO 클래스는 제거한 게시 유형에 따라 달라집니다.

스냅샷 또는 트랜잭션 게시를 제거하려면

  1. ServerConnection 클래스를 사용하여 게시자 연결을 만듭니다.

  2. TransPublication 클래스의 인스턴스를 만듭니다.

  3. 게시에 Name 대한 속성 및 DatabaseName 속성을 설정하고 1단계에서 만든 연결로 속성을 설정합니다 ConnectionContext .

  4. 게시가 IsExistingObject 있는지 확인하려면 속성을 확인합니다. 이 속성의 값이 false면 3단계의 게시 속성이 잘못 정의되었거나 게시가 존재하지 않습니다.

  5. Remove 메서드를 호출합니다.

  6. (선택 사항) 이 데이터베이스에 대한 다른 트랜잭션 게시가 없는 경우 다음과 같이 트랜잭션 게시에 대해 데이터베이스를 사용하지 않도록 설정할 수 있습니다.

    1. ReplicationDatabase 클래스의 인스턴스를 만듭니다. ConnectionContext 속성을 1단계의 ServerConnection 인스턴스로 설정합니다.

    2. LoadProperties 메서드를 호출합니다. 이 메서드가 false를 반환할 경우 데이터베이스가 있는지 확인합니다.

    3. EnabledTransPublishing 속성을 false설정합니다.

    4. CommitPropertyChanges 메서드를 호출합니다.

  7. 연결을 닫습니다.

병합 게시를 제거하려면

  1. ServerConnection 클래스를 사용하여 게시자 연결을 만듭니다.

  2. MergePublication 클래스의 인스턴스를 만듭니다.

  3. 게시에 Name 대한 속성 및 DatabaseName 속성을 설정하고 1단계에서 만든 연결로 속성을 설정합니다 ConnectionContext .

  4. 게시가 IsExistingObject 있는지 확인하려면 속성을 확인합니다. 이 속성의 값이 false면 3단계의 게시 속성이 잘못 정의되었거나 게시가 존재하지 않습니다.

  5. Remove 메서드를 호출합니다.

  6. (선택 사항) 이 데이터베이스에 대한 다른 병합 게시가 없는 경우 다음과 같이 병합 게시에 대해 데이터베이스를 사용하지 않도록 설정할 수 있습니다.

    1. ReplicationDatabase 클래스의 인스턴스를 만듭니다. ConnectionContext 속성을 1단계에서 만든 ServerConnection 인스턴스로 설정합니다.

    2. LoadProperties 메서드를 호출합니다. 이 메서드가 false를 반환하는 경우 데이터베이스가 있는지 확인합니다.

    3. EnabledMergePublishing 속성을 false설정합니다.

    4. CommitPropertyChanges 메서드를 호출합니다.

  7. 연결을 닫습니다.

예제(RMO)

다음은 트랜잭션 게시를 삭제하는 예제입니다. 이 데이터베이스에 대한 다른 트랜잭션 게시가 없으면 트랜잭션 게시도 사용하지 않도록 설정됩니다.

// Define the Publisher, publication database, 
// and publication names.
string publisherName = publisherInstance;
string publicationName = "AdvWorksProductTran";
string publicationDbName = "AdventureWorks2022";

TransPublication publication;
ReplicationDatabase publicationDb;

// Create a connection to the Publisher 
// using Windows Authentication.
ServerConnection conn = new ServerConnection(publisherName);

try
{
    conn.Connect();

    // Set the required properties for the transactional publication.
    publication = new TransPublication();
    publication.ConnectionContext = conn;
    publication.Name = publicationName;
    publication.DatabaseName = publicationDbName;

    // Delete the publication, if it exists and has no subscriptions.
    if (publication.LoadProperties() && !publication.HasSubscription)
    {
        publication.Remove();
    }
    else
    {
        // Do something here if the publication does not exist
        // or has subscriptions.
        throw new ApplicationException(String.Format(
            "The publication {0} could not be deleted. " +
            "Ensure that the publication exists and that all " +
            "subscriptions have been deleted.",
            publicationName, publisherName));
    }

    // If no other transactional publications exists,
    // disable publishing on the database.
    publicationDb = new ReplicationDatabase(publicationDbName, conn);
    if (publicationDb.LoadProperties())
    {
        if (publicationDb.TransPublications.Count == 0)
        {
            publicationDb.EnabledTransPublishing = false;
        }
    }
    else
    {
        // Do something here if the database does not exist.
        throw new ApplicationException(String.Format(
            "The database {0} does not exist on {1}.",
            publicationDbName, publisherName));
    }
}
catch (Exception ex)
{
    // Implement application error handling here.
    throw new ApplicationException(String.Format(
        "The publication {0} could not be deleted.",
        publicationName), ex);
}
finally
{
    conn.Disconnect();
}
' Define the Publisher, publication database, 
' and publication names.
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksProductTran"
Dim publicationDbName As String = "AdventureWorks2022"

Dim publication As TransPublication
Dim publicationDb As ReplicationDatabase

' Create a connection to the Publisher 
' using Windows Authentication.
Dim conn As ServerConnection = New ServerConnection(publisherName)

Try
    conn.Connect()

    ' Set the required properties for the transactional publication.
    publication = New TransPublication()
    publication.ConnectionContext = conn
    publication.Name = publicationName
    publication.DatabaseName = publicationDbName

    ' Delete the publication, if it exists and has no subscriptions.
    If publication.LoadProperties() And Not publication.HasSubscription Then
        publication.Remove()
    Else
        ' Do something here if the publication does not exist
        ' or has subscriptions.
        Throw New ApplicationException(String.Format( _
         "The publication {0} could not be deleted. " + _
         "Ensure that the publication exists and that all " + _
         "subscriptions have been deleted.", _
         publicationName, publisherName))
    End If

    ' If no other transactional publications exists,
    ' disable publishing on the database.
    publicationDb = New ReplicationDatabase(publicationDbName, conn)
    If publicationDb.LoadProperties() Then
        If publicationDb.TransPublications.Count = 0 Then
            publicationDb.EnabledTransPublishing = False
        End If
    Else
        ' Do something here if the database does not exist.
        Throw New ApplicationException(String.Format( _
         "The database {0} does not exist on {1}.", _
         publicationDbName, publisherName))
    End If
Catch ex As Exception
    ' Implement application error handling here.
    Throw New ApplicationException(String.Format( _
     "The publication {0} could not be deleted.", _
     publicationName), ex)
Finally
    conn.Disconnect()
End Try

다음은 병합 게시를 삭제하는 예제입니다. 이 데이터베이스에 대한 다른 병합 게시가 없으면 병합 게시도 사용하지 않도록 설정됩니다.

// Define the Publisher, publication database, 
// and publication names.
string publisherName = publisherInstance;
string publicationName = "AdvWorksSalesOrdersMerge";
string publicationDbName = "AdventureWorks2022";

MergePublication publication;
ReplicationDatabase publicationDb;

// Create a connection to the Publisher.
ServerConnection conn = new ServerConnection(publisherName);

try
{
    // Connect to the Publisher.
    conn.Connect();

    // Set the required properties for the merge publication.
    publication = new MergePublication();
    publication.ConnectionContext = conn;
    publication.Name = publicationName;
    publication.DatabaseName = publicationDbName;

    // Delete the publication, if it exists and has no subscriptions.
    if (publication.LoadProperties() && !publication.HasSubscription)
    {
        publication.Remove();
    }
    else
    {
        // Do something here if the publication does not exist
        // or has subscriptions.
        throw new ApplicationException(String.Format(
            "The publication {0} could not be deleted. " +
            "Ensure that the publication exists and that all " +
            "subscriptions have been deleted.",
            publicationName, publisherName));
    }

    // If no other merge publications exists,
    // disable publishing on the database.
    publicationDb = new ReplicationDatabase(publicationDbName, conn);
    if (publicationDb.LoadProperties())
    {
        if (publicationDb.MergePublications.Count == 0 && publicationDb.EnabledMergePublishing)
        {
            publicationDb.EnabledMergePublishing = false;
        }
    }
    else
    {
        // Do something here if the database does not exist.
        throw new ApplicationException(String.Format(
            "The database {0} does not exist on {1}.",
            publicationDbName, publisherName));
    }
}
catch (Exception ex)
{
    // Implement application error handling here.
    throw new ApplicationException(String.Format(
        "The publication {0} could not be deleted.",
        publicationName), ex);
}
finally
{
    conn.Disconnect();
}
' Define the Publisher, publication database, 
' and publication names.
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publicationDbName As String = "AdventureWorks2022"

Dim publication As MergePublication
Dim publicationDb As ReplicationDatabase

' Create a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)

Try
    ' Connect to the Publisher.
    conn.Connect()

    ' Set the required properties for the merge publication.
    publication = New MergePublication()
    publication.ConnectionContext = conn
    publication.Name = publicationName
    publication.DatabaseName = publicationDbName

    ' Delete the publication, if it exists and has no subscriptions.
    If (publication.LoadProperties() And Not publication.HasSubscription) Then
        publication.Remove()
    Else
        ' Do something here if the publication does not exist
        ' or has subscriptions.
        Throw New ApplicationException(String.Format( _
         "The publication {0} could not be deleted. " + _
         "Ensure that the publication exists and that all " + _
         "subscriptions have been deleted.", _
         publicationName, publisherName))
    End If

    ' If no other merge publications exists,
    ' disable publishing on the database.
    publicationDb = New ReplicationDatabase(publicationDbName, conn)
    If publicationDb.LoadProperties() Then
        If publicationDb.MergePublications.Count = 0 _
        And publicationDb.EnabledMergePublishing Then
            publicationDb.EnabledMergePublishing = False
        End If
    Else
        ' Do something here if the database does not exist.
        Throw New ApplicationException(String.Format( _
         "The database {0} does not exist on {1}.", _
         publicationDbName, publisherName))
    End If
Catch ex As Exception
    ' Implement application error handling here.
    Throw New ApplicationException(String.Format( _
     "The publication {0} could not be deleted.", _
     publicationName), ex)
Finally
    conn.Disconnect()
End Try

참고 항목

Replication System Stored Procedures Concepts
데이터 및 데이터베이스 개체 게시