Hi,
I need to find out all the tables in database, which has FK columns and dont have any Non-clustered index on them.
Kindly help.
Technology Tips and News
Hi,
I need to find out all the tables in database, which has FK columns and dont have any Non-clustered index on them.
Kindly help.
Use sys.foreign_keys
see
I used ,
SELECT OBJECT_NAME(f.parent_object_id) TableName, COL_NAME(fc.parent_object_id,fc.parent_column_id) ColName ,f.name FROM sys.foreign_keys AS f INNER JOIN sys.foreign_key_columns AS fc ON f.OBJECT_ID = fc.constraint_object_id INNER JOIN sys.tables t ON t.OBJECT_ID = fc.referenced_object_id
but I need to add which column has FK columns and dont have any Non-clustered index on them.
Thanks
I need output something like this;
TableName | ColumnName | ForeignKeys | Index Name | Index type |
as I mentioned above I able to find tableName,columnName Foreing on them using
SELECT OBJECT_NAME(f.parent_object_id) TableName, COL_NAME(fc.parent_object_id,fc.parent_column_id) ColName ,f.name FROM sys.foreign_keys AS f INNER JOIN sys.foreign_key_columns AS fc ON f.OBJECT_ID = fc.constraint_object_id INNER JOIN sys.tables t ON t.OBJECT_ID = fc.referenced_object_id
but I need Index Name with index type in this query.
I need a status of indexes on foreign key column.
so that I can further divied that data into non clustered ,clusterd indexes
TableName | ColumnName | ForeignKeys | Index Name | Index type |
Thanks
I don't have any query canned for the purpose, nor the time to compose one right now. (It's not a trivial problem, when it comes to multi-column keys.)
However, I would like to point out that once you have compiled this informtion, you should use it judiciously. Not having an index on an FK column can indeed cause performance issue, particularly with delete operations. But if deletions are out of the question, and nor there is any need to find data per this FK, any index may only add update over on the parent table.
Are you looking for the columns that do not have an index? Do you want to see on the fk a cluste
I need a status of indexes on foreign key column.
so that I can further divied that data into non clustered ,clusterd indexes
TableName ColumnName ForeignKeys Index Name Index type
I couldn't find what I needed on the web, so I wrote my own and posted it here: Identify Foreign Keys without Corresponding Indexes. The query will spit out a list of foreign keys that do not have corresponding indexes, along with comma-separated column lists for the foreign keys.
Best of luck!