![]() ![]() How to Drop a Table That has Dependent Objects in PostgreSQL? When we executed the DROP TABLE command, we encountered an error that says can’t drop a table that has dependent objects. Now, let’s try to drop the company_details table using the DROP TABLE: DROP TABLE comapny_details The above snippet shows that the employee_info table depends on the company_details table. Let’s describe the “employee_info” table using the “\d” command: \d employee_info Let’s execute the \d command to get all the details of the selected tables: \d company_details įrom the above snippet, you can observe that the company_id column is referred as a foreign key in the employee_info table. We have already created “company_details” and “employee_info” tables in our database. The below example will assist you in understanding the need for the CASCADE option.Įxample: How to Drop a Table That has Dependent Objects Using DROP TABLE Statement? ![]() So, any table that has some dependent objects can’t be deleted/dropped using the DROP TABLE statement. In PostgreSQL, a database can have multiple tables, and each table can have a relation with other tables. What is the Need For the CASCADE Option in PostgreSQL? This article will explain the Postgres DROP TABLE CASCADE statement with the help of examples. So, how to drop/delete a table that has dependent objects? Well! Thanks to the CASCADE option that allows us to drop a table along with its dependent objects. However, the DROP TABLE command can’t drop a table that contains dependent objects. In PostgreSQL, the DROP TABLE drops single or multiple tables. In PostgreSQL, the CASCADE option is used with the DROP TABLE command to drop the tables that have dependent objects. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |