大虾们:
我现在想把七八张表里面的每张表的两个字段,组合到一个视图中,做查询.在设计上遇到问题向大家请教一下.(数据库用的Sysbase, ) 1 有八张表,每张三个字段组合成一个视图不知道 sql server 或 Sysbase 数据库的视
图支持这么多字段不?
2 我现在想知道,从视图中查出来的数据是从哪张表里来的,请问这在视图中怎么样实现,如果视图中不能实现,代码中能吗? 希望遇到过这种问题的高手指点一下 , 有代码最好! 解决问题立即给分!
我现在想把七八张表里面的每张表的两个字段,组合到一个视图中,做查询.在设计上遇到问题向大家请教一下.(数据库用的Sysbase, ) 1 有八张表,每张三个字段组合成一个视图不知道 sql server 或 Sysbase 数据库的视
图支持这么多字段不?
2 我现在想知道,从视图中查出来的数据是从哪张表里来的,请问这在视图中怎么样实现,如果视图中不能实现,代码中能吗? 希望遇到过这种问题的高手指点一下 , 有代码最好! 解决问题立即给分!
e.g.:create view vw_tbA2C
select id = a.id
,a_field_1 = a.field_1
,a_field_2 = a.field_2
,b_field_1 = b.field_1
,c_field_2 = c.field_2
,c_field_3 = c.field_3 -- .. and so on
from tbA a, tbB b, tbC c
where a.id=b.id and a.id=c.id -- ..
我现在想把七八张表里面的每张表的两个字段,组合到一个视图中,做查询.在设计上遇到问题 向大家请教一下.(数据库用的Sysbase, ) 1 有八张表,每张三个字段组合成一个视图不知道 sql server 或 Sysbase 数据库的视
图支持这么多字段不? ---------------------------------
create view my_view
as
select a.* , b.* , c.* from a,b,c where a.id = b.id = c.id
2 我现在想知道,从视图中查出来的数据是从哪张表里来的,请问这在视图中怎么样实现,如 果视图中不能实现,代码中能吗?
希望遇到过这种问题的高手指点一下 , 有代码最好! 解决问题立即给分!这个直接查看视图的源码即可.
SELECT 来源表 = '表1',内容 = 表1.内容 FROM 表1
UNION ALL
SELECT 来源表 = '表2',内容 = 表2.内容 FROM 表2
if object_id('tempdb..#','U') is not null drop table #
create table #(test1 int)
set nocount on
declare @i int,@sql varchar(100)
set @i = 1
while @i >0
begin
begin try
set @i=@i+1
set @sql='alter table # add test'+ltrim(str(@i))+' int'
exec (@sql)
end try
begin catch
select error_message()
set @i=-@i
end catch
end
select 最大列数 = -(@i+1)
/*
CREATE TABLE 失败,因为表 '#' 中的列 'test1025' 超出了 1024 列的最大值。最大列数
-----------
1024
*/
if object_id('视图','V') is not null drop view 视图
GO
create view 视图 as
select 1 test1
GOset nocount on
declare @i int,@sql varchar(max)
set @i = 1
while @i >0
begin
begin try
set @i=@i+1
set @sql=replace(select object_definition(object_id('视图')),'create','alter')+',1 test'+ltrim(str(@i))
exec (@sql)
end try
begin catch
select error_message()
set @i=-@i
end catch
end
select 最大列数 = -(@i+1)
/*
CREATE VIEW 失败,因为视图 '视图' 中的列 'test1025' 超过了列的最大数目 1024。最大列数
-----------
1024
*/
if object_id('视图','V') is not null drop view 视图
GO
create view 视图 as
select 1 test1
GOset nocount on
declare @i int,@sql varchar(max)
set @i = 1
while @i >0
begin
begin try
set @i=@i+1
set @sql=replace(object_definition(object_id('视图')),'create','alter')+',1 test'+ltrim(str(@i))
exec (@sql)
end try
begin catch
select error_message()
set @i=-@i
end catch
end
select 最大列数 = -(@i+1)
/*
CREATE VIEW 失败,因为视图 '视图' 中的列 'test1025' 超过了列的最大数目 1024。最大列数
-----------
1024
*/