Concantenate columns in index

  • I have a problem. I want to concantenate an index in sql server 2005, i.e. i want it to look something like this:

    CREATE INDEX IND_SEARCH ON TAB_HOCKEYTEAMS

    (

    COLUMN1+COLUMN2

    )

    That gives me an syntax error. It works in Oracle, allthough you have to change the "+" to "||"...

    Is there anyway of doing this? Are there any other options?

    Tnx!! 🙂

  • Just use a comma instead of a plus

    CREATE INDEX IND_SEARCH ON TAB_HOCKEYTEAMS

    (

    COLUMN1,COLUMN2

    )

  • But I want the index to treat these two columns as one... When i do it like that, I will still get two columns seperated in the index.

  • Can you explain in detail what you are trying to achieve?

    I'm trying to fgure out why you would want them treated as a single column?

  • Danspojken (11/13/2009)


    But I want the index to treat these two columns as one...

    Why?

    If you want to do that, create a calculated column in the table, persist the column and then index that. Be aware that it'll only be of use if you have queries that concatenate the two columns before doing a comparison (which is usually a bad practice in the first place)

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply