commands

^

Set-DbaDbCompatibility

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.

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 | Version160}]
    [[-InputObject] <Database[]>]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Set-DbaDbCompatibility -SqlInstance sql2017a

Changes database compatibility level for all user databases on server sql2017a that have a Compatibility level that do not match

Example: 2
PS C:\> Set-DbaDbCompatibility -SqlInstance sql2019a -Compatibility Version150

Changes database compatibility level for all user databases on server sql2019a to Version150

Example: 3
PS C:\> Set-DbaDbCompatibility -SqlInstance sql2022b -Database Test -Compatibility Version160

Changes database compatibility level for database Test on server sql2022b to Version160

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 Availability values: https://learn.microsoft.com/en-us/dotnet/api/microsoft.sqlserver.management.smo.compatibilitylevel

Alias
Required False
Pipeline false
Default Value
-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