我正在尝试使用like_options
(https://www.postgresql.org/docs/9.5/static/sql-createtable.html)复制Postgres数据库中的一些表,其中指出使用INCLUDING ALL
也是复制CONSTRAINTS的简写(查询查询的信息{ {3}}并查找FK here
INCLUDING ALL是包含默认值的缩写形式 约束包括包括评论在内的存储的索引。
但是,在运行副本后,我没有看到原始表中预期的FK约束 - 假设因为新表为空我无法添加引用另一列中的列的FK约束表
create table lobby (LIKE command_center INCLUDING ALL);
SELECT
tc.constraint_name, tc.table_name, kcu.column_name,
ccu.table_name AS foreign_table_name,
ccu.column_name AS foreign_column_name
FROM
information_schema.table_constraints AS tc
JOIN information_schema.key_column_usage AS kcu
ON tc.constraint_name = kcu.constraint_name
JOIN information_schema.constraint_column_usage AS ccu
ON ccu.constraint_name = tc.constraint_name
WHERE constraint_type = 'FOREIGN KEY' AND (tc.table_name='command_center' OR tc.table_name='lobby');