Groups | Blog | Home
all groups > sql server msde > october 2005 >

sql server msde : Retrieving Indexes and SQL Relationships programatically


Mark Hollander
10/31/2005 12:00:00 AM
Hi All,

I have been able to retrieve the tables within a database automatically via
an sql query. Is there a way that I can retrieve the indexes (with the field
names they are indexing) and relationships (Fields plus tables they are
referencing).

What I am trying to achieve is this.
In VB.Net you have datasets. I would like to populate this dataset based on
the tables of the intended database progromatically and setup the
relationships and indexes rather than having to hardcode it in a class
everytime.

I also need to do this to ensure that when an update is sent out and there
have been database design changes that I can compare the structures,indexes
and relationships to what is needed and alter accordingly

Thanks in advance
Mark Hollander

Narayana Vyas Kondreddi
10/31/2005 8:57:57 AM
Look at the code of sp_helpindex, sp_fkeys and other related system stored
procedures. You could do this using sp_helptext, as in:

USE master
GO
EXEC sp_helptext sp_helpindex
GO

This will give you an idea of where the required information is stored in
the system tables.
--
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @ http://vyaskn.tripod.com/


[quoted text, click to view]
Hi All,

I have been able to retrieve the tables within a database automatically via
an sql query. Is there a way that I can retrieve the indexes (with the field
names they are indexing) and relationships (Fields plus tables they are
referencing).

What I am trying to achieve is this.
In VB.Net you have datasets. I would like to populate this dataset based on
the tables of the intended database progromatically and setup the
relationships and indexes rather than having to hardcode it in a class
everytime.

I also need to do this to ensure that when an update is sent out and there
have been database design changes that I can compare the structures,indexes
and relationships to what is needed and alter accordingly

Thanks in advance
Mark Hollander


AddThis Social Bookmark Button