To remove a table and all of its dependent items, use the CASCADE option.To delete a table, use the DROP TABLE statement.NOTICE: drop cascades to constraint pages_author_id_fkey on table pages The following message will be displayed if the DROP TABLE statement deletes the table's dependent objects: In this situation, either drop the author table first and then all dependent objects, or utilize the CASCADE option as described below:īoth the constraint in the page table and the author table are deleted by PostgreSQL. CASCADE to drop the dependent objects too. PostgreSQL generates an error because the constraint on the page table depends on the author table:ĮRROR: cannot drop table authors because other objects depend on itĭETAIL: constraint pages_author_id_fkey on table pages depends on table authors The author table is dropped using the DROP TABLE command in the following sentence: The authors and pages tables are created by the following: The output clearly shows that PostgreSQL delivered a notice rather than an error.Ģ) Eliminate a table with dependent elements. NOTICE: table "author" skipped because it is empty STRIKE TABLE You can utilize the IF EXISTS option in this way to get around the problem. The author table in the database is deleted with the following statement:ĭue to the absence of the author table, PostgreSQL generates an error. Let's look at a few instances of the PostgreSQL DROP TABLE statement in action. Keep in mind that in order to delete tables, you must be the superuser, schema owner, or table owner. You can add a list of tables, separated by commas, following the DROP TABLE keywords to delete several tables at once: Example: var1 : 'IF EXISTS (select from INFORMATIONSCHEMA.TABLES WHERE name ''Table' Suffix ''') then DROP TABLE Table'Suffix'' execute var1 But getting error near IF. ![]() For which I am trying the following query. If you don't specifically express it in the DROP TABLE statement, the RESTRICT option is the default. I am trying to drop table if it is exists in the present working database of PostgreSQL.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |