commands

^

Find-DbaSimilarTable

Author Jana Sattainathan (@SQLJana), sqljana.wordpress.com
Availability Windows, Linux, macOS

 

Want to see the source code for this command? Check out Find-DbaSimilarTable on GitHub.
Want to see the Bill Of Health for this command? Check out Find-DbaSimilarTable.

Synopsis

Returns all tables/views that are similar in structure by comparing the column names of matching and matched tables/views

Description

This function can either run against specific databases or all databases searching all/specific tables and views including in system databases. Typically one would use this to find for example archive version(s) of a table whose structures are similar. This can also be used to find tables/views that are very similar to a given table/view structure to see where a table/view might be used.

More information can be found here: https://sqljana.wordpress.com/2017/03/31/sql-server-find-tables-with-similar-table-structure/

Syntax

Find-DbaSimilarTable
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [[-Database] <Object[]>]
    [[-ExcludeDatabase] <Object[]>]
    [[-SchemaName] <String>]
    [[-TableName] <String>]
    [-ExcludeViews]
    [-IncludeSystemDatabases]
    [[-MatchPercentThreshold] <Int32>]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Find-DbaSimilarTable -SqlInstance DEV01

Searches all user database tables and views for each, returns all tables or views with their matching tables/views and match percent

Example: 2
PS C:\> Find-DbaSimilarTable -SqlInstance DEV01 -Database AdventureWorks

Searches AdventureWorks database and lists tables/views and their corresponding matching tables/views with match percent

Example: 3
PS C:\> Find-DbaSimilarTable -SqlInstance DEV01 -Database AdventureWorks -SchemaName HumanResource

Searches AdventureWorks database and lists tables/views in the HumanResource schema with their corresponding matching tables/views with match percent

Example: 4
PS C:\> Find-DbaSimilarTable -SqlInstance DEV01 -Database AdventureWorks -SchemaName HumanResource -Table Employee

Searches AdventureWorks database and lists tables/views in the HumanResource schema and table Employee with its corresponding matching tables/views with match percent

Example: 5
PS C:\> Find-DbaSimilarTable -SqlInstance DEV01 -Database AdventureWorks -MatchPercentThreshold 60

Searches AdventureWorks database and lists all tables/views with its corresponding matching tables/views with match percent greater than or equal to 60

Required Parameters

-SqlInstance

The target SQL Server instance or instances. This can be a collection and receive pipeline input

Alias
Required True
Pipeline true (ByValue)
Default Value

Optional Parameters

-SqlCredential

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

The database(s) to process - this list is auto-populated from the server. If unspecified, all databases will be processed.

Alias
Required False
Pipeline false
Default Value
-ExcludeDatabase

The database(s) to exclude - this list is auto-populated from the server

Alias
Required False
Pipeline false
Default Value
-SchemaName

If you are looking in a specific schema whose table structures is to be used as reference structure, provide the name of the schema. If no schema is provided, looks at all schemas

Alias
Required False
Pipeline false
Default Value
-TableName

If you are looking in a specific table whose structure is to be used as reference structure, provide the name of the table. If no table is provided, looks at all tables If the table name exists in multiple schemas, all of them would qualify

Alias
Required False
Pipeline false
Default Value
-ExcludeViews

By default, views are included. You can exclude them by setting this switch to $false This excludes views in both matching and matched list

Alias
Required False
Pipeline false
Default Value False
-IncludeSystemDatabases

By default system databases are ignored but you can include them within the search using this parameter

Alias
Required False
Pipeline false
Default Value False
-MatchPercentThreshold

The minimum percentage of column names that should match between the matching and matched objects. Entries with no matches are eliminated

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