Collations on indexes in SQL Server

后端 未结 3 483
隐瞒了意图╮
隐瞒了意图╮ 2021-01-11 17:28

I am interested if there is a possibility to specify collation for a column when creating index that is different from the collation of that column? And when indexed, are st

相关标签:
3条回答
  • 2021-01-11 17:39

    I don't believe you can. Although COLLATE is documented separately, you'll note that there are only 3 places listed where it can occur:

    • Creating or altering a database
    • Creating or altering a table column
    • Casting the collation of an expression

    Note that, for instance, in CREATE TABLE:

    <column_definition> ::=
    column_name <data_type>
        [ FILESTREAM ]
        [ COLLATE collation_name ] 
        ...
    

    that the COLLATE clause is explicitly mentioned.

    Whereas, in CREATE INDEX:

    CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name 
        ON <object> ( column [ ASC | DESC ] [ ,...n ] ) 
        ...
    

    note that all that is allowed here is a column - not a column definition, nor an expression.


    I believe the collation of each column within an index follows the collation of the underlying column(s) in the appropriate table. The database collation isn't used for much, so far as I'm aware, other than to supply a default collation to columns during CREATE/ALTER table statements.

    0 讨论(0)
  • 2021-01-11 17:43

    Try making an Indexed view and add the collation to the column in the select statement.

    0 讨论(0)
  • 2021-01-11 17:44

    You can create the calculated field with needed collation and create the index on this field.

    0 讨论(0)
提交回复
热议问题