3

I have a programming situation in which I have to check the uniqueness of a column of the table.

Say My table is employee table and I have added a column that is code. Now I have to prevent the insertion of MGR and mgr.

So that means I can not have 2 rows having case insensitive values.

How to add the check constraints ?

1 Answer 1

7

If you are using Oracle, you may add a unique index on the lowercase of your column.

create unique index <index_name> on <tablename>(lower(<column_name>)) 
Sign up to request clarification or add additional context in comments.

1 Comment

Just to complete the picture: there is a slight difference between a unique constraint and a unique index. An unique constraint can be the target of a foreign key constraint, a unique index can not. A unique index can be based on an expression (as done in this answer), a unique constraint can not be defined based on an expression.