首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求建一视图!该怎么处理

2012-01-13 
求建一视图!!!现有两个表,表1为学生表student字段为IDNameAge表2为教师表teacher字段为IDNameAgeDepartmen

求建一视图!!!
现有两个表,表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
(IDInt,
NameVarchar(10),
AgeInt)
Insert student Select 1, 'A ', 21
Union All Select 2, 'B ', 22

Create Table teacher
(IDInt,
NameVarchar(10),
AgeInt,
DepartmentVarchar(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
/*
IDName
1A
2B
11C
12D
*/

热点排行
Bad Request.