Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 How to know VIEW's column refer to which Table's?

Author  Topic 

xybook
Starting Member

3 Posts

Posted - 2006-09-29 : 13:59:03
[code]
create table t1 (id integer, name char(20), no integer identity(1,1))
create table t2 (id integer)
create view v12 as select t1.id t1_id, t2.* from t1, t2

insert into v12(t1_id) values(1)
insert into v12(id) values(1)

select * from v12
[/code]
How can I know v12.t1_id is equals to t1.id ?

I have try following SQLs but can not found enough information I need:
[code]
select * from INFORMATION_SCHEMA.VIEW_COLUMN_USAGE where view_name = 'v12'
select * from INFORMATION_SCHEMA.COLUMNS where table_name = 'v12'
select * from syscolumns where id = object_id('v12')
select * from sysobjects where name='v12'
[/code]

Welcomes and thanks for any comments :)

Bear

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-09-29 : 14:18:12
The best way is to look at the source code of the view, and figure it out from that.
exec sp_helptext 'MyViewName'


CODO ERGO SUM
Go to Top of Page

xybook
Starting Member

3 Posts

Posted - 2006-10-02 : 10:18:59
Thanks Michael.

Are there any better way to grab those info from system catalog instead of parsing the VIEW cotents?
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-10-02 : 10:39:45
quote:
Originally posted by xybook

Thanks Michael.

Are there any better way to grab those info from system catalog instead of parsing the VIEW cotents?



No.


CODO ERGO SUM
Go to Top of Page

xybook
Starting Member

3 Posts

Posted - 2006-10-02 : 11:15:01
Oh...that's too bad.

Anyway thank you for your help again.
Go to Top of Page
   

- Advertisement -