Skip to content
Advertisement

ADD CONSTRAINT on date part of a datetime column

I want to add a unique constraint on multiple columns. Usually, the following script should do the job:

How about if columns2 is DateTime and we want to set the constraint only on the date part? One solution could be using triggers but I need to avoid that.

Advertisement

Answer

You can use a computed column to virtually store the date part of the datetime column, and use it in the unique index.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement