是否可以创建具有不同列和列长度的2个或更多表的视图。我正在使用MS SQL。
例如,我有以下表格和列结构
USAAddress (door no, street char(30), city, zipcode (50))
GBPAddress (door no, addressline1 char(30), addressline2 char(30),
addressline3 city, country, postcode char(30), phoneno char(30))
是否可以使用不同的列和数据类型大小创建上述两个表的视图?
i) street would be mapped to addressline1
ii) zipcode would be mapped to postcode (zipcode is char(50) while postcode is char(30))
iii)phoneno is missing in USAAddress table, while it is present in GBPAddress table. I view should have phoneno but should show as empty in USAAddress.
答案 0 :(得分:0)
在视图中使用如下所示的查询应该可以解决问题:
select addressline1, postcode, phoneno
from GBPAddress
union all
select street, left(zipcode,30), null
from USAAddress
作为旁注,将VARCHAR用于长度不同的长文本字段更为常见。而不是在数据长度相当固定时使用CHAR。