to the database, but not to the master. I can't see anything in
INFORMATION_SCHEMA.CHECK_CONSTRAINTS or
INFORMATION_SCHEMA.KEY_COLUMN_USAGE
An sa ID for the master sees everything however.
Thanks for your help
Pachydermitis[posted and mailed, please reply in news]
Pachydermitis (dedejavu@.hotmail.com) writes:
> Hi I need to see all the indexes in a database. The ID has dbo rights
> to the database, but not to the master. I can't see anything in
> INFORMATION_SCHEMA.CHECK_CONSTRAINTS or
> INFORMATION_SCHEMA.KEY_COLUMN_USAGE
> An sa ID for the master sees everything however.
Don't really see where INFORMATION_SCHEMA comes in. There is no
information about indexes there. Generally, I prefer using the
system tables, because they hold the complete set of information.
To see all indexes in a database (save those on system tables):
SELECT "table" = object_name(id), name
FROM sysindexes i
WHERE indid BETWEEN 1 AND 254
AND indexproperty(id, name, 'IsHypothetical') = 0
AND indexproperty(id, name, 'IsStatistics') = 0
AND indexproperty(id, name, 'IsAutoStatistics') = 0
AND objectproperty(id, 'IsMsShipped') = 0
ORDER BY "table", name
--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||dedejavu@.hotmail.com (Pachydermitis) wrote in message news:<4f954dcf.0309190902.1d421bf4@.posting.google.com>...
> Hi I need to see all the indexes in a database. The ID has dbo rights
> to the database, but not to the master. I can't see anything in
> INFORMATION_SCHEMA.CHECK_CONSTRAINTS or
> INFORMATION_SCHEMA.KEY_COLUMN_USAGE
> An sa ID for the master sees everything however.
> Thanks for your help
> Pachydermitis
Hi,
This would give you the info what you are seeking..
select name, object_name(id) from sysindexes
-Manoj|||Manoj Rajshekar (manrajshekar@.yahoo.com) writes:
> This would give you the info what you are seeking..
> select name, object_name(id) from sysindexes
And a lot more he is not interested in. He will also get the names of
heap tables (tables without clustered indexes), hypothetcial indexes,
statistics and location of text data. This SELECT filters this kind
of information:
SELECT "table" = object_name(id), name
FROM sysindexes i
WHERE indid BETWEEN 1 AND 254
AND indexproperty(id, name, 'IsHypothetical') = 0
AND indexproperty(id, name, 'IsStatistics') = 0
AND indexproperty(id, name, 'IsAutoStatistics') = 0
AND objectproperty(id, 'IsMsShipped') = 0
ORDER BY "table", name
and also filters indexes on system tables.
--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Thanks Erland,
I have been able to get the TableName and IndexNames (along with a few
I don't want _WA_. . .) but I can't seem to get the column names or
get rid of the _WA_ ones.
I was trying to get TableName, IndexName, ColumnName
SELECT obj.[name],ind.[name] FROM sysindexes ind
inner join sysobjects obj on ind.[id]=obj.[id]
ORDER BY obj.[name],ind.indid
Thanks again
Pachydermitis|||Pachydermitis (dedejavu@.hotmail.com) writes:
> I have been able to get the TableName and IndexNames (along with a few
> I don't want _WA_. . .) but I can't seem to get the column names or
> get rid of the _WA_ ones.
Had you used the query I suggested, you would have been relieved from the
_WA "indexes". (Which are statistics and hypothetical indexes.)
> I was trying to get TableName, IndexName, ColumnName
Here is a query that gives this. For multi-column indexes you get one
row per index. If you want all columns for an index on one line, you
will have run some iteration.
SELECT "table" = object_name(i.id), i.name,
isclustered = indexproperty(i.id, i.name, 'IsClustered'),
"column" = col_name(i.id, ik.colid), ik.keyno
FROM sysindexes i
JOIN sysindexkeys ik ON i.id = ik.id
AND i.indid = ik.indid
WHERE i.indid BETWEEN 1 AND 254
AND indexproperty(i.id, name, 'IsHypothetical') = 0
AND indexproperty(i.id, name, 'IsStatistics') = 0
AND indexproperty(i.id, name, 'IsAutoStatistics') = 0
AND objectproperty(i.id, 'IsMsShipped') = 0
ORDER BY "table", "isclustered" DESC, i.name, ik.keyno
--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp
No comments:
Post a Comment