Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Find Common Link Between Two Tables in Database without Key Constraints

$
0
0
Does anyone know of a tool, script, procedure, or otherwise that will solve this problem?CREATE TABLE [Table 1] (Id varchar,TableTwoId varchar,OtherData varchar )CREATE TABLE [Table 2] (Id varchar,MoreData varchar )What is the link between these two tables?I have databases that have zero keys defined, no foreign key constraints, no unique value constraints. I cannot assume that an Identity column is the Id. The end game is be able to output that [Table 1].[TableTwoId] = [Table 2].[Id] but cannot assume that all linkage in the database will be as simple as saying "if the field name contains a table name + Id then it is the Id in that table." Currently have written a script that will cycle through all columns and start identifying keys in singular tables based on the distinctness of the values in each column (i.e. Column1 is 99% distinct so is the unique value). It will also combine columns if the linkage is the combination of one or more columns from Table 1 = the same number of columns in Table 2. This takes a long time, and it somewhat unreliable as IDENTITY columns may seem to relate to one another when they don't.Any help would be appreciated.

Viewing all articles
Browse latest Browse all 3145

Trending Articles