HINT: Truncate table "order_items" at the same time, or use TRUNCATE. You'll get notice ERROR: cannot truncate a table referenced in a foreign key constraintÄETAIL: Table "order_items" references "orders". As opposed to the application level cascading controlled by the cascade option, we can also define database level referential integrity actions: on update and. delete cascade on one-to-many relationships is often combined with delete-orphan cascade, which will emit a DELETE for the related row if the child object is. Suppose you had two tables orders and order_items where the order_items table references the orders.order_id column. CASCADE construct which was introduced in PostgreSQL 8.2, which will not only delete all data from the main table, but will CASCADE to all the referenced tables. In comes its extended form, the TRUNCATE TABLE. You however can't use TRUNCATE TABLE unqualified, if the table you are truncating has foreign key references from other tables. Our preferred is the TRUNCATE TABLE approach because it's orders of magnitude faster than the DELETE FROM construct. This model explicitly defines the following referential actions: If you delete a Tag, the corresponding tag assignment is also deleted in TagOnPosts, using the Cascade referential action If you delete a User, the author is removed from all posts by setting the field value to Null, because of the SetNull referential action. Device table has the following columns: As you can predict, configid on my Device table is a foreign key referencing id column on the Deviceconfig So I have added this constraint on my Device table. Though it is a rare occurrence, we have had occasions where we need to purge ALL data from a table.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |