database 这两种关系对于联合操作是否兼容?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/15370394/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Are these two relations compatible for a union operation?
提问by amorimluc
I'm not sure if the following two relations are compatible for a union:
我不确定以下两个关系是否与联合兼容:
R: <- schema name
B
1
2
2
3
3
And:
和:
Q: -< schema name
A  B
5  1
6  1
4  2
3  4
I want to do the union: Q U R. Can I? What's the result?
我想做工会:QU R。可以吗?结果如何?
回答by Mosty Mostacho
The union operator requires that both relations are union-compatible. This means that they are required to have the same set of attributes. Note that this concept goes slightly beyond than sharing the same amount of attributes. This is because it also considers the content of the attribute.
联合运算符要求两个关系是联合兼容的。这意味着它们必须具有相同的属性集。请注意,此概念略高于共享相同数量的属性。这是因为它还考虑了属性的内容。
This doesn't mean that both attributes should have the same name but rather that both attributes should, and I'm really walking away from relational algebra with this example, have a similar "data type". There is no such a thing in relation algebra but I think that if you have a programming background you'll easily get it by thinking on that concept.
这并不意味着两个属性都应该具有相同的名称,而是两个属性都应该具有类似的“数据类型”,而且我在这个示例中真正摆脱了关系代数。在关系代数中没有这样的东西,但我认为如果你有编程背景,你会很容易通过思考这个概念来获得它。
EG: Consider the following relations:
EG:考虑以下关系:
- Person(FirstName, LastName)
- Country(Name, Population)
- 人(名字,姓氏)
- 国家(姓名、人口)
In this case, Person and Country are not union-compatible as they do not share the same set of attributes, even though they share the same amount of attributes.
在这种情况下,Person 和 Country 不是联合兼容的,因为它们不共享相同的属性集,即使它们共享相同数量的属性。
回答by amorimluc
In fact, these two relations are not compatible for a union: they have a different number of attributes. Found the answer after some more research.
事实上,这两种关系对于联合是不兼容的:它们具有不同数量的属性。经过更多研究后找到了答案。
回答by Muhammad Haroon
Two table are said to be union compatible if both the table have same number of attributes (column) and corresponding attributes have the same data type (int,char,float,date etc.). Corresponding attributes means first attributes of both relations, then second and so on.
如果两个表具有相同数量的属性(列)并且对应的属性具有相同的数据类型(int、char、float、date 等),则称这两个表是联合兼容的。对应的属性意味着两个关系的第一个属性,然后是第二个,依此类推。
union compatible:
A: (First_name (char), Last_name(char), Date_of_Birth(date))
B: (FName(char),LName(char),DOB(date))
Both table have 3 attributes and of same date type.  
联合兼容:
A: (First_name (char), Last_name(char), Date_of_Birth(date)) 
B: (FName(char),LName(char),DOB(date))
两个表都有 3 个属性并且日期类型相同。  
Not compatible:
A: (First_name (char), Last_name(char), Date_of_Birth(date))
B: (FName(char),LName(char),PhoneNumber(number))  
不兼容:
A: (First_name (char), Last_name(char), Date_of_Birth(date)) 
B: (FName(char),LName(char),PhoneNumber(number))  
(The third attributes are different.)
(第三个属性不同。)
回答by John
Check here for more detailed definition of Union Compatibility 
In your case the two relations which you mentioned are not Union Compatibility because they do not have same number of attributes [schema R have one one attribute and schema Q have two attributes]  
So you can not apply UNION operation on those schemas.
在此处查看联合兼容性的更详细定义
在您的情况下,您提到的两个关系不是联合兼容性,因为它们没有相同数量的属性[架构 R 有一个属性,架构 Q 有两个属性]  
所以你不能申请对这些模式的 UNION 操作。

