Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
创建多个具有关系的表,而无需选中";参考资料;在postgresql中_Postgresql_Database Migration - Fatal编程技术网

创建多个具有关系的表,而无需选中";参考资料;在postgresql中

创建多个具有关系的表,而无需选中";参考资料;在postgresql中,postgresql,database-migration,Postgresql,Database Migration,我正在尝试将SQL Server数据库迁移到Postgres 作为一个例子,考虑我们有3个表-A,B.C. B包含A&C的外键 但我们是按照A,B,C的顺序创建表的 由于没有可用的“表C”,创建“表B”时将抛出错误,表示不存在任何关系 那么,在事务或会话中创建表的过程中,有没有办法“不检查引用” 在实际场景中,我有大约76个表。约束可以随时添加到表中,而不仅仅是在表创建期间,因此一个选项是先创建所有表,然后再创建所有约束 因此,不是: Create Table AAA ( ... Const

我正在尝试将SQL Server数据库迁移到Postgres

作为一个例子,考虑我们有3个表-A,B.C.

B包含A&C的外键

但我们是按照A,B,C的顺序创建表的

由于没有可用的“表C”,创建“表B”时将抛出错误,表示不存在任何关系

那么,在事务或会话中创建表的过程中,有没有办法“不检查引用”


在实际场景中,我有大约76个表。

约束可以随时添加到表中,而不仅仅是在表创建期间,因此一个选项是先创建所有表,然后再创建所有约束

因此,不是:

Create Table AAA (
  ... Constraint fk_AAA_BBB Foreign Key (BBBcode) References BBB (BBBcode)
)
Create Table BBB (
  ...
)
您将运行:

Create Table AAA (
  ...
)
Create Table BBB (
  ...
)
Alter Table Add Constraint fk_AAA_BBB Foreign Key (BBBcode) References BBB (BBBcode)

通常先创建所有表,然后运行ALTERTABLE语句来定义外键。没有别的办法,不必太复杂。只要改变顺序A,C,B。