Remove‑SqlDscDatabase - dsccommunity/SqlServerDsc GitHub Wiki

SYNOPSIS

Removes a database from a SQL Server Database Engine instance.

SYNTAX

ServerObject

Remove-SqlDscDatabase -ServerObject <Server> -Name <String> [-Force] [-Refresh] [-DropConnections]
 [-WhatIf] [-Confirm] [<CommonParameters>]

DatabaseObject

Remove-SqlDscDatabase -DatabaseObject <Database> [-Force] [-DropConnections]
 [-WhatIf] [-Confirm] [<CommonParameters>]

DESCRIPTION

This command removes a database from a SQL Server Database Engine instance.

EXAMPLES

EXAMPLE 1

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$databaseObject = $serverObject | Get-SqlDscDatabase -Name 'MyDatabase'
$databaseObject | Remove-SqlDscDatabase

Removes the database named MyDatabase.

EXAMPLE 2

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$serverObject | Remove-SqlDscDatabase -Name 'MyDatabase'

Removes the database named MyDatabase.

EXAMPLE 3

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$serverObject | Remove-SqlDscDatabase -Name 'MyDatabase' -Force

Removes the database named MyDatabase without prompting for confirmation.

EXAMPLE 4

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$serverObject | Remove-SqlDscDatabase -Name 'MyDatabase' -DropConnections -Force

Drops all active connections to the database named MyDatabase and then removes it without prompting for confirmation. This is useful when the database has active connections that prevent removal.

PARAMETERS

-DatabaseObject

Specifies a database object to remove.

Type: Database
Parameter Sets: DatabaseObject
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

-DropConnections

Specifies that all active connections to the database should be dropped before removing the database. This sets the database to single-user mode with immediate rollback of active transactions, which forcibly disconnects all users and allows the database to be removed even when there are active connections.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-Force

Specifies that the database should be removed without any confirmation.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-Name

Specifies the name of the database to be removed.

Type: String
Parameter Sets: ServerObject
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Refresh

Specifies that the ServerObject's databases should be refreshed before trying to remove the database object. This is helpful when databases could have been modified outside of the ServerObject, for example through T-SQL. But on instances with a large amount of databases it might be better to make sure the ServerObject is recent enough, or pass in DatabaseObject.

Type: SwitchParameter
Parameter Sets: ServerObject
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-ServerObject

Specifies current server connection object.

Type: Server
Parameter Sets: ServerObject
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

-Confirm

Prompts you for confirmation before running the cmdlet.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

None.

NOTES

RELATED LINKS

⚠️ **GitHub.com Fallback** ⚠️