首页 > IT职业 > IT职场 > PostgreSQL中drop表失败怎么办

PostgreSQL中drop表失败怎么办
当您创建包含许多具有外键约束,视图,触发器,函数等的表的复杂数据库结构时,将隐式创建对象之间的依赖关系网。例如,具有外键约束的表取决于它引用的表。
为了确保整个数据库结构的完整性, PostgreSQL确保您不能删除其他对象仍然依赖的对象。
DROP TABLE products; NOTICE: constraint orders_product_no_fkey on table orders depends on table products ERROR: cannot drop table products because other objects depend on it HINT: Use DROP ... CASCADE to drop the dependent objects too.
解决方法如下:
该错误消息包含一个有用的提示:如果您不想麻烦地删除所有依赖对象,则可以运行
DROP TABLE products CASCADE;
所有从属对象将被删除。在这种情况下,它不会删除orders表,而只会删除外键约束。
推荐:postgresql教程
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3378/viewspace-2834035/ ,如需转载,请注明出处,否则将追究法律责任。