Skip to content

Commit a5ea9d5

Browse files
authored
SQL-363: Merge pull request #342 from jim-dotcom/check-indexes
Script to Generate All Indexes in a Database in SQL
2 parents c53baa7 + 602e694 commit a5ea9d5

5 files changed

+74
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
SELECT
2+
TABLE_NAME,
3+
INDEX_NAME,
4+
COLUMN_NAME,
5+
NON_UNIQUE,
6+
INDEX_TYPE
7+
FROM
8+
information_schema.STATISTICS
9+
WHERE
10+
TABLE_SCHEMA = 'University'
11+
ORDER BY
12+
TABLE_NAME,
13+
INDEX_NAME,
14+
SEQ_IN_INDEX;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
SELECT
2+
TABLE_NAME,
3+
INDEX_NAME,
4+
COLUMN_NAME
5+
FROM
6+
information_schema.STATISTICS
7+
WHERE
8+
TABLE_SCHEMA = 'University'
9+
ORDER BY
10+
TABLE_NAME,
11+
INDEX_NAME,
12+
SEQ_IN_INDEX;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
SELECT
2+
t.relname AS table_name,
3+
i.relname AS index_name,
4+
a.attname AS column_name
5+
FROM
6+
pg_class t
7+
JOIN
8+
pg_index ix ON t.oid = ix.indrelid
9+
JOIN
10+
pg_class i ON i.oid = ix.indexrelid
11+
JOIN
12+
pg_attribute a ON a.attrelid = t.oid AND a.attnum = ANY(ix.indkey)
13+
WHERE
14+
t.relkind = 'r'
15+
AND t.relnamespace = 'public'::regnamespace
16+
ORDER BY
17+
t.relname,
18+
i.relname;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
SELECT
2+
schemaname,
3+
tablename,
4+
indexname,
5+
indexdef
6+
FROM
7+
pg_indexes
8+
WHERE
9+
schemaname = 'public'
10+
ORDER BY
11+
tablename,
12+
indexname;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
SELECT
2+
t.name AS table_name,
3+
ind.name AS index_name,
4+
col.name AS column_name,
5+
ind.is_unique,
6+
ind.type_desc AS index_type
7+
FROM
8+
sys.indexes ind
9+
INNER JOIN
10+
sys.index_columns ic ON ind.object_id = ic.object_id AND ind.index_id = ic.index_id
11+
INNER JOIN
12+
sys.columns col ON ic.object_id = col.object_id AND ic.column_id = col.column_id
13+
INNER JOIN
14+
sys.tables t ON ind.object_id = t.object_id
15+
WHERE
16+
t.is_ms_shipped = 0
17+
ORDER BY
18+
t.name, ind.name, ic.key_ordinal;

0 commit comments

Comments
 (0)