求建一视图!!!
现有两个表,表1为学生表
student
字段为 ID Name Age
表2 为教师表
teacher
字段为 ID Name Age Department等
现欲实现将两个表中的内容整合在一起建一个视图
字段为 ID Name
即包含所有的教师和学生的ID和Name
------解决方案--------------------Select ID, Name From student
Union All
Select ID, Name From teacher
------解决方案--------------------CREATE VIEW 整合
AS
select id , name from student
union all
select id , name from teacher
------解决方案--------------------Create View V_TEST
AS
Select ID, Name From student
Union All
Select ID, Name From teacher
GO
------解决方案--------------------yuxing117(雨行) ( ) 信誉:100 Blog 2007-03-20 11:24:53 得分: 0
Union关键字是不可以用在视图里面的!!
有别的方法么?
---------------
"Union关键字是不可以用在视图里面的 "?!沒聽說
Create Table student
(ID Int,
Name Varchar(10),
Age Int)
Insert student Select 1, 'A ', 21
Union All Select 2, 'B ', 22
Create Table teacher
(ID Int,
Name Varchar(10),
Age Int,
Department Varchar(10))
Insert teacher Select 11, 'C ', 28, 'CC '
Union All Select 12, 'D ', 32, 'DD '
GO
Create View V_TEST
AS
Select ID, Name From student
Union All
Select ID, Name From teacher
GO
Select * From V_TEST
GO
Drop Table student, teacher
Drop View V_TEST
--Result
/*
ID Name
1 A
2 B
11 C
12 D
*/