Find Common Link Between Two Tables in Database without Key Constraints

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

  • Please DO NOT CROSS POST.

    You already have a thread here http://www.sqlservercentral.com/Forums/Topic1703612-3412-1.aspx. Creating a new post only serves to fragment the discussion.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • ALTER INDEX ALL ON [dbo].[Find Common Link Between Two Tables in Database without Key Constraints] REBUILD PARTITION = ALL WITH ( PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, ONLINE = OFF, SORT_IN_TEMPDB = OFF )

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply