Sql server 构造具有不同列和列长度的表的视图
可以创建两个或多个具有不同列和列长度的表的视图。我正在使用MS SQL 例如,我有下面的表和列结构Sql server 构造具有不同列和列长度的表的视图,sql-server,Sql Server,可以创建两个或多个具有不同列和列长度的表的视图。我正在使用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)) 是否可以创建具有
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.
在视图中使用如下查询应该可以做到这一点:
作为旁注,对于长度不同的长文本字段,使用VARCHAR更为常见。当数据的长度相当固定时,不使用CHAR 你试过了吗?是的,这是可能的。
select addressline1, postcode, phoneno
from GBPAddress
union all
select street, left(zipcode,30), null
from USAAddress