January 24, 2013 at 12:03 am
Hi All,
One of simple delete query is taking more than 10hrs to execute. There are more than 12 foreign keys dependent on that table. Query is like this,
Delete from Some_Table where table_sr_key !=-99 and sector_id=@some_code
But if we execute the same query after updating the statistics of the table then the query get executed in few minutes.
Please help me how me handle this issue so that those query will execute without any manual intervention.
Thanks in advance,
Debanjan
January 24, 2013 at 12:13 am
debanjan.ray (1/24/2013)
One of simple delete query is taking more than 10hrs to execute. There are more than 12 foreign keys dependent on that table. Query is like this,Delete from Some_Table where table_sr_key !=-99 and sector_id=@some_code
Two questions :
How much data it contains ?
and do FK are with "on cascade delete" option ?
Also post table defintion along with index definition
-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
January 24, 2013 at 12:22 am
Maybe you should create a job to automatically update your statistics, since they're clearly out of date.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
January 24, 2013 at 12:31 am
That table contains only 1lac rows.
Table PK:
Table_sr_key, table_eff_strt_dt
Table FK(10 Fks like same structure):
PRD_SR_KEY, EFF_STRT_DT
REFERENCES Product (PRD_SR_KEY, EFF_STRT_DT)
Table is refernced by more than 20 table.
January 24, 2013 at 12:34 am
still you havent posted what all i asked
anyways
i will suggest you to take batch approach for "Deletion" . and i dont think "periodic statistics updation will help you much HERE "
-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
January 24, 2013 at 12:35 am
do FK are with "on cascade delete" option ?
-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
January 24, 2013 at 12:39 am
No.. On delete cascade option is not there with FK....
January 24, 2013 at 12:43 am
debanjan.ray (1/24/2013)
That table contains only 1lac rows.Table PK:
Table_sr_key, table_eff_strt_dt
Table FK(10 Fks like same structure):
PRD_SR_KEY, EFF_STRT_DT
REFERENCES Product (PRD_SR_KEY, EFF_STRT_DT)
Table is refernced by more than 20 table.
This is primarily a English-speaking site, so 95% of the people here don't know what you mean with lac (or lakh). Also read the following article about keeping the integrity of your database when deleting rows in a table referenced by FKs:
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
January 24, 2013 at 12:56 am
Koen Verbeeck (1/24/2013)
Do not disable foreign keys
Any other reference ?
-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
January 24, 2013 at 12:58 am
Bhuvnesh (1/24/2013)
Koen Verbeeck (1/24/2013)
Do not disable foreign keysAny other reference ?
Maybe. I'm sure Google can help you out 😉
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply