Self referencing join

  • I have two tables:

    Table1 self referencing join parent of Table2.

    When the code looks for data in Table2 70% of the time it wants it by the parent id from Table1. Both these tables have xml (geometry points) with several tags and can have a lot of records in them since they are for design.

    table design:

    Table1

    T1id uniqueidentifier

    Geometry xml

    Parentid uniqueidentifier Self FK

    other fields

    Table2

    T2Id uniqueidentifier

    T1Id uniqueidentifier FK

    Geometry xml

    other fields

    Question (theory): Will a CTE from Table1 be fast enough to where I do not need another FK in table2 referencing the parent in Table1 ie:

    Table2

    T2Id uniqueidentifier

    T1Id uniqueidentifier FK

    T1Parent uniqueidentifier FK

    Geometry xml

    other fields

  • I don't entirely understand the structure that you're presenting, so I'm not sure I'm going to answer your question here.

    CTE's are just queries. They aren't fast or slow, just as queries are not fast or slow all by themselves. It really depends on what you do within them. Using a CTE is really no different than using a derived table, except CTE's provide some unique functionality that derived tables do not (and they can make for much easier to read code in some ways).

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Yeah that is kind of what I was asking. Thanks

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

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