Perfomance due to foreign key

  • I have a table with primari key. which is refrenced across 63 columns in 40 + tables

    Now when i tried to delete one record in this table it takes lot over 5 min to delete it.

    is their batter way to optimize delete??

    Thanks

  • Take a look at the execution plan. It's possible that you're seeing scans across all those other tables. Maybe some indexes are in order.

    "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

  • There may also be triggers in place doing writes somewhere.

    ----------------------------------------------------

  • jagat.patel (4/1/2014)


    I have a table with primari key. which is refrenced across 63 columns in 40 + tables

    Now when i tried to delete one record in this table it takes lot over 5 min to delete it.

    is their batter way to optimize delete??

    Thanks

    You probably have a large table or tables that have a foreign key reference to the table you are deleting from without an index on the FK column. In that case SQL Server has to scan the entire table to see if it is OK to delete the row. An index on the FK column would prevent the table scan.

    Generally, you should have an index on a foreign key column. It is not created by default when you created a foreign key

  • ...which is refrenced across 63 columns in 40 + tables...

    Just wondering: Why is a PK column refernced by more than one column of another table?

    There are cases when it is required (e.g. a hierarchy table referencing a persons table).

    But there are also cases, where a multi-reference indicates some "room for improvement" of the DB design...



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • LutzM (5/3/2014)


    ...which is refrenced across 63 columns in 40 + tables...

    Just wondering: Why is a PK column refernced by more than one column of another table?

    There are cases when it is required (e.g. a hierarchy table referencing a persons table).

    But there are also cases, where a multi-reference indicates some "room for improvement" of the DB design...

    I was thinking the same thing when I read the original post 🙂

    ----------------------------------------------------

Viewing 6 posts - 1 through 5 (of 5 total)

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