SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Deleting the records without foreign key


Deleting the records without foreign key

Author
Message
sql_reporting
sql_reporting
SSC Rookie
SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)

Group: General Forum Members
Points: 37 Visits: 169
i have datawarehouse database where there is only primary key and no foreign keys.

I have a condition from one table and based on that condition i have to delete the records from other tables.

I am trying to use joins and delete the records based on that condition. Is this right way or else anyother way to delete.
Eugene Elutin
Eugene Elutin
SSCertifiable
SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)

Group: General Forum Members
Points: 6312 Visits: 5478
raghuveer126 (10/18/2012)
i have datawarehouse database where there is only primary key and no foreign keys.

I have a condition from one table and based on that condition i have to delete the records from other tables.

I am trying to use joins and delete the records based on that condition. Is this right way or else anyother way to delete.


1. It might be the right way.
2. There is a possibility that there are other ways exist which you can use to delete.

That about the best answer I can think of, based on details you have provided.

_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
EamonSQL
EamonSQL
SSC Veteran
SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)

Group: General Forum Members
Points: 272 Visits: 181
Create a trigger that seeks out any child records and deletes them if found.

Eamon:-)
sql_reporting
sql_reporting
SSC Rookie
SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)

Group: General Forum Members
Points: 37 Visits: 169
Hi Thank you for the reply..

I did inner join put a where clause and deleted one table there were x rows affected but when i try to put one more table from the inner joins i used in the delete statement it is not deleting the related records in that table, it says 0 rows affected.

If it has no foreign keys than how do i know which table to delete first...
Jason-299789
Jason-299789
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2615 Visits: 3232
I would be very nervous about deleting records from a DW as the nature of them can mean that while its ok to delete from dimensions based on one set of requirements, you could actually be deleting valid records that are required by other Facts that dont meet those requirements.

Can you explain why you need to delete these records and what type of DW it is? (eg Star Schema, Snowflake, Incremental/Snapshot load)

_________________________________________________________________________
SSC Guide to Posting and Best Practices
Bhuvnesh
Bhuvnesh
SSCertifiable
SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)

Group: General Forum Members
Points: 6832 Visits: 4076
EamonSQL (10/19/2012)
Create a trigger that seeks out any child records and deletes them if found.

Eamon:-)
i didnt see any comment from OP that he wants to delete data with every DML operation .its by choice or i would say manual call

-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
Bhuvnesh
Bhuvnesh
SSCertifiable
SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)

Group: General Forum Members
Points: 6832 Visits: 4076
raghuveer126 (10/22/2012)
I did inner join put a where clause and deleted one table there were x rows affected but when i try to put one more table from the inner joins i used in the delete statement it is not deleting the related records in that table, it says 0 rows affected.
If it has no foreign keys than how do i know which table to delete first...
first you should verify the data by select it before deleting it. another thing one query will delete the data from one table at a time (i havent seen anything link Delete table1, table2 from .............) then another query for second deletion

-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
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