0

How to delete many columns from linked tables together

regarding constraints

3rd Feb 2017, 6:10 PM
Ranjeet Kumar
4 Answers
+ 1
Sorry, "linked" means "related by a constraint"?
3rd Feb 2017, 7:52 PM
Álvaro
+ 1
(1/2) Ok. Well, that depends on the relationship between the tables, and the sequence of the delete statements. Say you have a lookup table: **************** * id1 * name 1 * * id2 * name 2 * **************** and a fact table ************************** * date1 * id1 * amount 1 * * date2 * id1 * amount 2 * * date2 * id2 * amount 3 * ************************** and the id column in the fact table has a n:1 relationship with the id in the lookup table (i.e. a foreign key). If you try to delete first from the lookup table, you'll not be able to, because you'll be violating the constraint. If you delete from the fact table first, that'll be fine.
4th Feb 2017, 7:52 AM
Álvaro
+ 1
(2/2) Still, if you need to remove first from the fact table, prior to that you'll need to deactivate the constraint. But at the risk that your db will be inconsistent.
4th Feb 2017, 7:54 AM
Álvaro
0
yes@Alvaro
3rd Feb 2017, 8:08 PM
Ranjeet Kumar