|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Monday, May 06, 2013 3:04 PM
Points: 283,
Visits: 356
|
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: 2 days ago @ 1:07 PM
Points: 18,733,
Visits: 12,332
|
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Yesterday @ 2:59 PM
Points: 49,
Visits: 112
|
|
I like the ides of this, I would add ordering the columns as they are defined in the key. And for the programmers in my area I would add a statement in the where clause so they only got the table they need instead of every table on the database.
SELECT p.TABLE_NAME, c.CONSTRAINT_NAME, c.COLUMN_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS p inner join INFORMATION_SCHEMA.KEY_COLUMN_USAGE c on c.TABLE_NAME = p.TABLE_NAME AND c.CONSTRAINT_NAME = p.CONSTRAINT_NAME WHERE CONSTRAINT_TYPE = 'PRIMARY KEY' AND p.TABLE_NAME = 'name_here' ORDER by c.TABLE_NAME, c.ordinal_position
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Yesterday @ 2:59 PM
Points: 49,
Visits: 112
|
|
Here is a query to find all the indexes on a table.
select r.[name] as table_name, i.[name] as index_name, c.[name] as column_name FROM sys.index_columns l inner join sys.tables r on l.object_id = r.object_id inner join sys.indexes i on l.object_id = i.object_id and l.index_id = i.index_id inner join sys.columns c on l.object_id = c.object_id and l.column_id = c.column_id where r.[name] = 'table_name_here' order by r.[name], l.index_id, l.key_ordinal
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Yesterday @ 10:44 AM
Points: 46,
Visits: 205
|
|
| Nice idea. I tested it on 2000, 2005, and 2008. It works well on all of them.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 12:56 AM
Points: 14,
Visits: 49
|
|
I ran this and got an empty results set. Is there something that needs to be done to populate these schema views? This is a totally new subject for me. I was under the impression that these views would be already defined in the system and can just be queried as in this article.
Dana
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Yesterday @ 2:59 PM
Points: 49,
Visits: 112
|
|
It could be either your table does not have an index set up, or the database doesn't have any tables that have indexes.
You need to be connected to the database where the table exists for either of these to work.
I don't think anything needs to be done for this to work, but then I'm not a DBA.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 12:56 AM
Points: 14,
Visits: 49
|
|
I have plenty of tables, I've been using it for a while. And there are indexes. And stored procedures and functions. But still, the script returns an empty results set. It seems that something must be done to populate these views. I'm no DBA either, except by necessity. The database is on my shared hosting, so maybe there are some constraints there. I know there are other things that I do not have access to. For example, there have been scripts that access certain system stored procedures and are meant to help with optimizing and finding where things could be sped up. They don't work, either. But in those cases I get an error message that states that I don't have privileges to those procedures. This doesn't complain, it just returns and empty set. *shrug*
Dana
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Yesterday @ 2:59 PM
Points: 49,
Visits: 112
|
|
| I talked to my DBA and he said these are automatically updated. So it must be a permissions issue that is stopping you from seeing anything.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 12:56 AM
Points: 14,
Visits: 49
|
|
belowery (6/29/2012) I talked to my DBA and he said these are automatically updated. So it must be a permissions issue that is stopping you from seeing anything.
Thank you. At least I know. I suppose I can get along without them. I have thus far. 
Dana
|
|
|
|