How do I index a database column

后端 未结 9 1845
难免孤独
难免孤独 2020-12-12 15:51

Hopefully, I can get answers for each database server.

For an outline of how indexing works check out: How does database indexing work?

相关标签:
9条回答
  • 2020-12-12 16:17

    To create indexes following stuff can be used:

    1. Creates an index on a table. Duplicate values are allowed: CREATE INDEX index_name ON table_name (column_name)

    2. Creates a unique index on a table. Duplicate values are not allowed: CREATE UNIQUE INDEX index_name ON table_name (column_name)

    3. Clustered Index: CREATE CLUSTERED INDEX CL_ID ON SALES(ID);

    4. Non-clustered index:
      CREATE NONCLUSTERED INDEX NONCI_PC ON SALES(ProductCode);

    Refer: http://www.codeproject.com/Articles/190263/Indexes-in-MS-SQL-Server for details.

    0 讨论(0)
  • 2020-12-12 16:19

    Sql Server 2005 gives you the ability to specify a covering index. This is an index that includes data from other columns at the leaf level, so you don't have to go back to the table to get columns that aren't included in the index keys.

    create nonclustered index my_idx on my_table (my_col1 asc, my_col2 asc) include (my_col3);
    

    This is invaluable for a query that has my_col3 in the select list, and my_col1 and my_col2 in the where clause.

    0 讨论(0)
  • 2020-12-12 16:19

    For python pytables, indexes don't have names and they are bound to single columns:

    tables.columns.column_name.createIndex()
    
    0 讨论(0)
提交回复
热议问题