Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Deleting the records without foreign key Expand / Collapse
Author
Message
Posted Thursday, October 18, 2012 8:55 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, July 18, 2014 9:35 AM
Points: 25, Visits: 153
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.
Post #1374421
Posted Thursday, October 18, 2012 9:35 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, July 4, 2014 3:55 AM
Points: 2,836, Visits: 5,062
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!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1374446
Posted Friday, October 19, 2012 5:28 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, June 2, 2014 1:52 AM
Points: 115, Visits: 141
Create a trigger that seeks out any child records and deletes them if found.

Eamon
Post #1374748
Posted Monday, October 22, 2012 5:14 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, July 18, 2014 9:35 AM
Points: 25, Visits: 153
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...
Post #1375784
Posted Tuesday, October 23, 2012 12:45 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, July 18, 2014 9:09 AM
Points: 870, Visits: 2,385
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
Post #1375854
Posted Tuesday, October 23, 2012 4:31 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 3:47 AM
Points: 2,837, Visits: 3,953
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
Post #1375949
Posted Tuesday, October 23, 2012 4:35 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 3:47 AM
Points: 2,837, Visits: 3,953
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
Post #1375950
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse