Author | Garry Bargsley, blog.garrybargsley.com |
Availability | Windows, Linux, macOS |
Want to see the source code for this command? Check out Set-DbaDbCompatibility on GitHub.
Want to see the Bill Of Health for this command? Check out Set-DbaDbCompatibility.
Sets the compatibility level for SQL Server databases.
Sets the current database compatibility level for all databases on a server or list of databases passed in to the function.
Set-DbaDbCompatibility
[[-SqlInstance] <DbaInstanceParameter[]>]
[[-SqlCredential] <PSCredential>]
[[-Database] <String[]>]
[[-Compatibility] {Version60 | Version65 | Version70 | Version80 | Version90 | Version100 | Version110 | Version120 | Version130 | Version140 | Version150}]
[[-TargetCompatibility] <Int32>]
[[-InputObject] <Database[]>]
[-EnableException]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
PS C:\> Set-DbaDbCompatibility -SqlInstance localhost\sql2017
Changes database compatibility level for all user databases on server localhost\sql2017 that have a Compatibility level that do not match
PS C:\> Set-DbaDbCompatibility -SqlInstance localhost\sql2017 -TargetCompatibility 12
Changes database compatibility level for all user databases on server localhost\sql2017 to Version120
PS C:\> Set-DbaDbCompatibility -SqlInstance localhost\sql2017 -Database Test -TargetCompatibility 12
Changes database compatibility level for database Test on server localhost\sql2017 to Version 120
The target SQL Server instance or instances.
Alias | |
Required | False |
Pipeline | false |
Default Value |
SqlLogin 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 or databases to process. If unspecified, all databases will be processed.
Alias | |
Required | False |
Pipeline | false |
Default Value |
The target compatibility level version. Same format as returned by Get-DbaDbCompatibility
Version90 = SQL Server 2005
Version100 = SQL Server 2008
Version110 = SQL Server 2012
Version120 = SQL Server 2014
Version130 = SQL Server 2016
Version140 = SQL Server 2017
Version150 = SQL Server 2019
Alias | |
Required | False |
Pipeline | false |
Default Value |
Deprecated parameter. Please use Compatibility instead.
The target compatibility level version. This is an int and follows Microsoft's versioning:
9 = SQL Server 2005
10 = SQL Server 2008
11 = SQL Server 2012
12 = SQL Server 2014
13 = SQL Server 2016
14 = SQL Server 2017
15 = SQL Server 2019
Alias | |
Required | False |
Pipeline | false |
Default Value | 0 |
Accepted Values | 9,10,11,12,13,14,15 |
A collection of databases (such as returned by Get-DbaDatabase)
Alias | |
Required | False |
Pipeline | true (ByValue) |
Default Value |
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
Alias | wi |
Required | False |
Pipeline | false |
Default Value |
Prompts for confirmation of every step. For example:
Are you sure you want to perform this action?
Performing the operation "Update database" on target "pubs on SQL2016\VNEXT".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):
Alias | cf |
Required | False |
Pipeline | false |
Default Value |