我正在尋找一個查詢在sql服務器,將顯示我的數據庫中的所有外鍵索引列表。我有一堆索引在我的數據庫中,一些是在表的外鍵,我正在尋找放棄除了外鍵和主鍵的索引外的所有索引。查詢獲得外鍵索引
Q
查詢獲得外鍵索引
-1
A
回答
2
也許第一個答案的扭曲能做到這一點的?:雅
SELECT
sc.name + '.' + t.name as tableName,
OBJECT_NAME(fkc.constraint_object_id) AS [FKey-Name],
OBJECT_NAME(fkc.referenced_object_id) ReferencedTable,
c.name as ColumnName
, i.name AS ReferencedKeyName
FROM sys.foreign_key_columns fkc
JOIN sys.index_columns ic ON ic.object_id = fkc.parent_object_id
AND ic.column_id = fkc.parent_column_id
JOIN sys.indexes i ON i.index_id = ic.index_id
AND i.object_id = ic.object_id
JOIN sys.columns c ON c.object_id = ic.object_id
AND c.column_id = ic.column_id
JOIN sys.tables t ON t.object_id = c.object_id
JOIN sys.schemas sc ON sc.schema_id = t.schema_id
WHERE t.is_ms_shipped = 0
ORDER BY tableName, OBJECT_NAME(fkc.constraint_object_id), columnName
0
SELECT fk.name,
OBJECT_NAME(fk.parent_object_id) AS parent_table,
c1.name AS parent_column,
OBJECT_NAME(fk.referenced_object_id) AS referenced_table,
c2.name AS referenced_column
FROM sys.foreign_keys fk
INNER JOIN sys.foreign_key_columns fkc
ON fk.object_id = fkc.constraint_object_id
INNER JOIN sys.columns c1
ON fkc.parent_object_id = c1.object_id
AND fkc.parent_column_id = c1.column_id
INNER JOIN sys.columns c2
ON fkc.referenced_object_id = c2.object_id
AND fkc.referenced_column_id = c2.column_id
2
下面是一個查詢,它會根據您的需要來做。
SELECT
sc.name + '.' + t.name as tableName,
i.name as indexName,
c.name as columnName
FROM sys.foreign_key_columns fkc
JOIN sys.index_columns ic ON ic.object_id = fkc.parent_object_id
AND ic.column_id = fkc.parent_column_id
JOIN sys.indexes i ON i.index_id = ic.index_id
AND i.object_id = ic.object_id
JOIN sys.columns c ON c.object_id = ic.object_id
AND c.column_id = ic.column_id
JOIN sys.tables t ON t.object_id = c.object_id
JOIN sys.schemas sc ON sc.schema_id = t.schema_id
where t.is_ms_shipped = 0
ORDER BY tableName, indexName, columnName
相關問題
- 1. 索引外鍵優化查詢
- 2. 多鍵索引:在查詢
- 3. lucene無鍵索引查詢
- 4. 索引外鍵
- 5. MySQL查詢外鍵引用主鍵
- 6. MySql外鍵索引
- 7. 外鍵和索引
- 8. 索引外鍵列
- 9. 外鍵和索引
- 10. 查詢外鍵
- 11. Redbeanphp - 從外鍵索引獲取數據
- 12. 在連接查詢中沒有選擇外鍵索引
- 13. 使用外鍵和範圍進行查詢的索引設計
- 14. 比較值,並獲得主鍵/索引
- 15. Django查詢 - 檢索關聯的外鍵
- 16. 主鍵和索引 - 查詢性能
- 17. 多鍵索引慢範圍查詢
- 18. 插入查詢汽車索引主鍵
- 19. Mongodb - 查詢多鍵索引文檔
- 20. PostgreSQL的查詢來獲得外鍵多列
- 21. 獲得來自ORM查詢所有外鍵在父表 - Django的
- 22. 從外鍵查詢主鍵
- 23. Django:外鍵查詢
- 24. 用外鍵查詢
- 25. MySQL外鍵查詢
- 26. ORMLite查詢外鍵
- 27. 查詢與外鍵
- 28. 獲取外鍵的查詢集
- 29. SQL查詢來獲取一個外鍵
- 30. 從查詢集獲取所有外鍵
,這樣給了我限制,但不是索引名 –
,這樣仍然只是給我的表和列,但而不是索引名稱 –