Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Perfomance due to foreign key


Perfomance due to foreign key

Author
Message
jagat.patel
jagat.patel
SSC-Addicted
SSC-Addicted (427 reputation)SSC-Addicted (427 reputation)SSC-Addicted (427 reputation)SSC-Addicted (427 reputation)SSC-Addicted (427 reputation)SSC-Addicted (427 reputation)SSC-Addicted (427 reputation)SSC-Addicted (427 reputation)

Group: General Forum Members
Points: 427 Visits: 258
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
Grant Fritchey
Grant Fritchey
SSCoach
SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)

Group: General Forum Members
Points: 17603 Visits: 32267
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

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
MMartin1
MMartin1
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1112 Visits: 2015
There may also be triggers in place doing writes somewhere.

----------------------------------------------------
How to post forum questions to get the best help
Michael Valentine Jones
Michael Valentine Jones
Hall of Fame
Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)

Group: General Forum Members
Points: 3254 Visits: 11771
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
LutzM
LutzM
SSCertifiable
SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)

Group: General Forum Members
Points: 7001 Visits: 13559
...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
How to post performance related questions
Links for Tally Table , Cross Tabs and Dynamic Cross Tabs , Delimited Split Function
MMartin1
MMartin1
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1112 Visits: 2015
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 :-)

----------------------------------------------------
How to post forum questions to get the best help
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search