Movatterモバイル変換


[0]ホーム

URL:



Facebook
Postgres Pro
Facebook
Downloads

5.12. Dependency Tracking

When you create complex database structures involving many tables with foreign key constraints, views, triggers, functions, etc. you implicitly create a net of dependencies between the objects. For instance, a table with a foreign key constraint depends on the table it references.

To ensure the integrity of the entire database structure,PostgreSQL makes sure that you cannot drop objects that other objects still depend on. For example, attempting to drop the products table we had considered inSection 5.3.5, with the orders table depending on it, would result in an error message such as this:

DROP TABLE products;NOTICE:  constraint orders_product_no_fkey on table orders depends on table productsERROR:  cannot drop table products because other objects depend on itHINT:  Use DROP ... CASCADE to drop the dependent objects too.

The error message contains a useful hint: if you do not want to bother deleting all the dependent objects individually, you can run:

DROP TABLE products CASCADE;

and all the dependent objects will be removed. In this case, it doesn't remove the orders table, it only removes the foreign key constraint. (If you want to check whatDROP ... CASCADE will do, runDROP withoutCASCADE and read theNOTICE messages.)

All drop commands inPostgreSQL support specifyingCASCADE. Of course, the nature of the possible dependencies varies with the type of the object. You can also writeRESTRICT instead ofCASCADE to get the default behavior, which is to prevent the dropping of objects that other objects depend on.

Note: According to the SQL standard, specifying eitherRESTRICT orCASCADE is required. No database system actually enforces that rule, but whether the default behavior isRESTRICT orCASCADE varies across systems.

Note: Foreign key constraint dependencies and serial column dependencies fromPostgreSQL versions prior to 7.3 arenot maintained or created during the upgrade process. All other dependency types will be properly created during an upgrade from a pre-7.3 database.


PrevHomeNext
Other Database ObjectsUpData Manipulation
Go to PostgreSQL 9.4
By continuing to browse this website, you agree to the use of cookies. Go toPrivacy Policy.

[8]ページ先頭

©2009-2025 Movatter.jp