---
title: "Remove-DbaDbSequence"
description: "Removes database sequence objects from SQL Server instances."
url: "https://dbatools.io/Remove-DbaDbSequence/"
availability: "Windows, Linux, macOS"
tags: ["Data", "Sequence", "Table"]
author: "Adam Lancaster, github.com/lancasteradam"
source: "https://github.com/dataplat/dbatools/blob/master/public/Remove-DbaDbSequence.ps1"
last_updated: "2024-01-01"
---

# Remove-DbaDbSequence

## Synopsis

Removes database sequence objects from SQL Server instances.

## Description

Removes sequence objects from SQL Server databases, freeing up schema namespace and cleaning up unused database objects.  
Sequences are commonly used for generating unique numeric values and may need removal during application changes or database cleanup.  
  
When used without a pipeline, the function will first retrieve matching sequences using Get-DbaDbSequence with the provided parameters, then remove them.  
Pipeline input from Get-DbaDbSequence allows for selective removal after review or filtering.

## Syntax

```powershell
Remove-DbaDbSequence
    [-SqlInstance] <DbaInstanceParameter[]>
    [-SqlCredential <PSCredential>]
    [-Database <String[]>]
    [-Sequence <String[]>]
    [-Schema <String[]>]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Remove-DbaDbSequence -InputObject <Sequence[]>
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

```

## Examples

### Example 1: Removes the sequence TestSequence in the TestDB database on the sqldev01 instance

```powershell
PS C:\> Remove-DbaDbSequence -SqlInstance sqldev01 -Database TestDB -Sequence TestSequence
```

### Example 2: Using a pipeline this command gets all sequences on SRV1, lets the user select those to remove and then...

```powershell
PS C:\> Get-DbaDbSequence -SqlInstance SRV1 | Out-GridView -Title 'Select sequence(s) to drop' -OutputMode Multiple | Remove-DbaDbSequence
```

Using a pipeline this command gets all sequences on SRV1, lets the user select those to remove and then removes the selected sequences.  

### Required Parameters

##### -SqlInstance

The target SQL Server instance or instances.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | True |
| Pipeline | false |
| Default Value |  |

##### -InputObject

Accepts sequence objects piped from Get-DbaDbSequence for removal.  
This allows you to first review sequences with Get-DbaDbSequence before selectively removing them.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | True |
| Pipeline | true (ByValue) |
| Default Value |  |

### Optional Parameters

##### -SqlCredential

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).  
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.  
For MFA support, please use Connect-DbaInstance.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -Database

Specifies which databases to search for sequences to remove. Accepts wildcards for pattern matching.  
Use this to limit sequence removal to specific databases instead of searching all databases on the instance.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -Sequence

Specifies the name(s) of the sequences to remove. Accepts wildcards for pattern matching.  
Use this when you know the exact sequence names or want to remove sequences matching a naming pattern.

| Property | Value |
| --- | --- |
| Alias | Name |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -Schema

Filters sequences to remove by schema name. Accepts wildcards for pattern matching.  
Useful when you need to remove sequences from specific schemas only, such as during application module cleanup.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.  
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.  
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value | False |

##### -WhatIf

Shows what would happen if the command were to run. No actions are actually performed.

| Property | Value |
| --- | --- |
| Alias | wi |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -Confirm

Prompts you for confirmation before executing any changing operations within the command.  
This is the default. Use -Confirm:$false to suppress these prompts.

| Property | Value |
| --- | --- |
| Alias | cf |
| Required | False |
| Pipeline | false |
| Default Value |  |

## Outputs

**PSCustomObject**

**Returns one object per sequence removed, with the following properties:**

- ComputerName: The name of the computer where the sequence was dropped
- InstanceName: The SQL Server instance name
- SqlInstance: The full SQL Server instance name (computer\instance)
- Database: The name of the database containing the sequence
- Sequence: The fully qualified sequence name in format schema.name
- SequenceName: The name of the sequence without schema qualification
- SequenceSchema: The schema name containing the sequence
- Status: The result of the drop operation (either "Dropped" on success or the error message on failure)
- IsRemoved: Boolean indicating if the sequence was successfully dropped ($true) or failed ($false)

---

Part of [dbatools](https://dbatools.io/), a free and open source PowerShell module for SQL Server administration. Full command index: https://dbatools.io/commands/
