Author | Chrissy LeMaire (@cl), netnerds.net |
Availability | Windows, Linux, macOS |
Want to see the source code for this command? Check out Invoke-DbaDbClone on GitHub.
Want to see the Bill Of Health for this command? Check out Invoke-DbaDbClone.
Clones a database schema and statistics
Clones a database schema and statistics.
This can be useful for testing query performance without requiring all the space needed for the data in the database.
Read more:
- https://sqlperformance.com/2016/08/sql-statistics/expanding-dbcc-clonedatabase
- https://support.microsoft.com/en-us/help/3177838/how-to-use-dbcc-clonedatabase-to-generate-a-schema-and-statistics-only
Thanks to Microsoft Tiger Team for the code and idea https://github.com/Microsoft/tigertoolbox/
Invoke-DbaDbClone
[[-SqlInstance] <DbaInstanceParameter[]>]
[[-SqlCredential] <PSCredential>]
[[-Database] <String[]>]
[[-InputObject] <Database[]>]
[[-CloneDatabase] <String[]>]
[-ExcludeStatistics]
[-ExcludeQueryStore]
[-UpdateStatistics]
[-EnableException]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
PS C:\> Invoke-DbaDbClone -SqlInstance sql2016 -Database mydb -CloneDatabase myclone
Clones mydb to myclone on sql2016
PS C:\> Get-DbaDatabase -SqlInstance sql2016 -Database mydb | Invoke-DbaDbClone -CloneDatabase myclone, myclone2 -UpdateStatistics
Updates the statistics of mydb then clones to myclone and myclone2
The target SQL Server instance or instances.
Alias | |
Required | False |
Pipeline | false |
Default Value |
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.
Alias | |
Required | False |
Pipeline | false |
Default Value |
The database to clone - this list is auto-populated from the server.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Enables piping from Get-DbaDatabase
Alias | |
Required | False |
Pipeline | true (ByValue) |
Default Value |
The name(s) to clone to.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Exclude the statistics in the cloned database
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Exclude the QueryStore data in the cloned database
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Update the statistics prior to cloning (per Microsoft Tiger Team formula)
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
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.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Shows what would happen if the command were to run. No actions are actually performed.
Alias | wi |
Required | False |
Pipeline | false |
Default Value |
Prompts you for confirmation before executing any changing operations within the command.
Alias | cf |
Required | False |
Pipeline | false |
Default Value |