Home Forums SQL Server 7,2000 T-SQL To change an existing column to a UNIQUE Column? RE: To change an existing column to a UNIQUE Column?

  • rajagopalanseeth (3/13/2013)


    Hi,

    I have a table that has around 5000 records. I have a requirement that i want to change a varchar column to UNIQUE, but the problem is that there are many rows that has empty values in it. If i try to change the column to UNIQUE, i am getting an error that "The CREATE UNIQUE INDEX statement terminated because a duplicate key was found for the object name. The duplicate key value is ()". My requirement is that the Column should have a Unique values in select cases while adding a new rows, sometimes null values can also be present. Is there a way for me to create a UNIQUE for that column. If i create a Trigger will that work out? If so how.

    Thanks.

    Your definition contradicts what you want to do. You can't have both a unique constraint and duplicate values.

    Not quite sure what you mean by unique values in select cases.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/