commands

^

Set-DbaDbCompatibility

Author Garry Bargsley, http://blog.garrybargsley.com/
Availability Windows, Linux, macOS

 

Synopsis

Sets the compatibility level for SQL Server databases.

Description

Sets the current database compatibility level for all databases on a server or list of databases passed in to the function.

Syntax

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>]

 

Examples

 

Example: 1
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

Example: 2
PS C:\> Set-DbaDbCompatibility -SqlInstance localhost\sql2017 -TargetCompatibility 12

Changes database compatibility level for all user databases on server localhost\sql2017 to Version120

Example: 3
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

Optional Parameters

-SqlInstance

The target SQL Server instance or instances.

Alias
Required False
Pipeline false
Default Value
-SqlCredential

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
-Database

The database or databases to process. If unspecified, all databases will be processed.

Alias
Required False
Pipeline false
Default Value
-Compatibility

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
-TargetCompatibility

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
-InputObject

A collection of databases (such as returned by Get-DbaDatabase)

Alias
Required False
Pipeline true (ByValue)
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.

Alias
Required False
Pipeline false
Default Value False
-WhatIf

Shows what would happen if the command were to run

Alias wi
Required False
Pipeline false
Default Value
-Confirm

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

 

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.