[英]DB2 Relational Tables
Is it possible to create a database such that there are 2 tables across 2 different schemas within the database who reference each other? 是否可以创建一个数据库,以便在数据库中的2个不同模式中有2个表互相引用?
I would like to clarify my question with an example. 我想用一个例子来澄清我的问题。
Consider the tables, EMPLOYEE (empID, empName, deptId)
and DEPARTMENT (deptId, deptName)
. 考虑表
EMPLOYEE (empID, empName, deptId)
和DEPARTMENT (deptId, deptName)
。 We can impose a foreign key constraint on the EMPLOYEE.deptId
. 我们可以对
EMPLOYEE.deptId
施加外键约束。 In this case can I have these two tables across two different schemas and still impose the constraint? 在这种情况下,我可以将这两个表包含在两个不同的模式中并且仍然施加约束吗?
The answer is yes. 答案是肯定的。 DB2 does not require both tables in a foreign key relationship to reside in the same schema.
DB2不需要外键关系中的两个表都位于同一模式中。
You mean via foreign keys or in joins? 您是指通过外键还是联接?
Sure: Just always prefix the table name with the schema name and a "." 当然:只需在表名前加上模式名和“。”即可。 (dot).
(点)。 Like so:
像这样:
select t1.id, t2.id from schema1.table1 t1 join schema2.table2 t2 on t1.fid = t2.id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.