< Back

Find-DbaSimilarTable

Mon Jan 13, 2020 10:11 am

NAME Find-DbaSimilarTable



SYNOPSIS

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

tables/views





SYNTAX

Find-DbaSimilarTable [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]> [[-SqlCredential]

<Pscredential>] [[-Database] <System.Object[]>] [[-ExcludeDatabase] <System.Object[]>] [[-SchemaName] <String>]

[[-TableName] <String>] [-ExcludeViews <Switch>] [-IncludeSystemDatabases <Switch>] [[-MatchPercentThreshold]

<Int>] [-EnableException <Switch>] [<CommonParameters>]





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/3 ... structure/





PARAMETERS

-Database [<System.Object[]>]

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

be processed.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-EnableException [<Switch>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-ExcludeDatabase [<System.Object[]>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-ExcludeViews [<Switch>]

By default, views are included. You can exclude them by setting this switch to $false

This excludes views in both matching and matched list



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-IncludeSystemDatabases [<Switch>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-MatchPercentThreshold [<Int>]

The minimum percentage of column names that should match between the matching and matched objects.

Entries with no matches are eliminated



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SchemaName [<String>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlCredential [<Pscredential>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlInstance [<Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-TableName [<String>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



NOTES





Tags: Table

Author: Jana Sattainathan (@SQLJana), http://sqljana.wordpress.com



Website: https://dbatools.io

Copyright: (c) 2018 by dbatools, licensed under MIT

License: MIT https://opensource.org/licenses/MIT



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



RELATED LINKS

https://dbatools.io/Find-DbaSimilarTable