当前位置: 代码迷 >> Sql Server >> 都来看看,新手不会的小疑点
  详细解决方案

都来看看,新手不会的小疑点

热度:50   发布时间:2016-04-24 10:11:36.0
都来看看,新手不会的小问题,在线等
是这样 我要建一个 查询A\B\V\D\E 五张表 所有的数据  建一个view sql语句如何写?
------解决方案--------------------
5张表的结构一样  就用select * from a union all select * from b union ...一直下去
如果不一样,就用null来顶多余的列 还是union all 一直下去
------解决方案--------------------
create view xxx
as 
select *
from a
union all 
select * from b
union all 
.....
------解决方案--------------------
如果用union all
前提是这个五张表,字段数目是一致的,不一致的要手工加列
------解决方案--------------------

create view [视图名]
as
 select [字段列表] from A
 union all
 select [字段列表] from B
 union all
 select [字段列表] from V
 union all
 select [字段列表] from D
 union all
 select [字段列表] from E

PS: 每个子查询的字段列表字段数须一致.
  相关解决方案