Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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 使用主键/外键同步所有postgres db表的行_Postgresql_Foreign Keys_Primary Key - Fatal编程技术网

Postgresql 使用主键/外键同步所有postgres db表的行

Postgresql 使用主键/外键同步所有postgres db表的行,postgresql,foreign-keys,primary-key,Postgresql,Foreign Keys,Primary Key,我有一个有30个表的postgres数据库。主表“general_data”有一列“building_code”,所有其他表都将其用作外键。 我需要的是同步所有表中的“building_code”列,这意味着如果在“general_data”中添加一行,则在所有表中创建一行,该行在“building_code”中具有相同的值(其他列保持为空) 是否有一个SQL函数可以做到这一点?您需要为此创建一个触发器。但是,在insert过程中,您会在其他表的notnull列中添加什么内容呢?谢谢您提供的提示

我有一个有30个表的postgres数据库。主表“general_data”有一列“building_code”,所有其他表都将其用作外键。 我需要的是同步所有表中的“building_code”列,这意味着如果在“general_data”中添加一行,则在所有表中创建一行,该行在“building_code”中具有相同的值(其他列保持为空)


是否有一个SQL函数可以做到这一点?

您需要为此创建一个触发器。但是,在insert过程中,您会在其他表的
notnull
列中添加什么内容呢?谢谢您提供的提示,我将对此进行研究。我正在开发一个web应用程序,它可以动态访问数据库中的表。webapp用户稍后将插入除“建筑代码”之外的列的值,因此现在必须保持为空。它们主要是“文本”、“整数”和“实数”。我没有触发功能方面的经验,有没有最佳实践想法如何处理这个问题?thnx