I need a query to see if a table already has any indexes on it.
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- php PDO::FETCH_ASSOC doesnt detect select after ba
- Bulk update SQL Server C#
On SQL Server, this will list all the indexes for a specified table:
This query will list all tables without an index:
And this is an interesting MSDN FAQ on a related subject:
Querying the SQL Server System Catalog FAQ
On Oracle:
Determine all indexes on table:
Determine columns indexes and columns on index:
References:
Created a stored procedure to list indexes for a table in database in SQL Server
If you're using MySQL you can run
SHOW KEYS FROM table
orSHOW INDEXES FROM table
If you just need the indexed columns EXEC sp_helpindex 'TABLE_NAME'
check this as well This gives an overview of associated constraints across a database. Please also include facilitating where condition with table name of interest so gives information faster.
select a.TABLE_CATALOG as DB_name,a.TABLE_SCHEMA as tbl_schema, a.TABLE_NAME as tbl_name,a. CONSTRAINT_NAME as constraint_name,b.CONSTRAINT_TYPE from INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE a join INFORMATION_SCHEMA.TABLE_CONSTRAINTS b on a.CONSTRAINT_NAME=b.CONSTRAINT_NAME