Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a table

desigin like this

date token_no
09/02/2015 12:50:00 PM 1
09/02/2015 12:51:00 PM 2

i want to create a unique constraints by combaining the date and token no

ie one token no for date

how can create constraints
Posted
Updated 18-Feb-15 20:14pm

1 solution

Well, in SQL Server 2008, there's a new datatype called "DATE" - you could use that column and create an index on that.

You could of course also add a computed column of type "DATE" to your table and just fill the date portion of the DATETIME column into that computed column, make it PERSISTED, and index it. Should work just fine!

Something like that:

SQL
ALTER TABLE dbo.Entries
   ADD DateOnly as CAST(CompositionDate AS DATE) PERSISTED

CREATE UNIQUE INDEX UX_Entries ON Entries(DateOnly, Slug)


Ref.Page
http://stackoverflow.com/questions/620561/how-to-create-a-unique-constraint-just-on-the-date-part-of-a-datetime[^]
 
Share this answer
 
Comments
Mahesh K.M 19-Feb-15 5:34am    
how can do this in oracle ,because i am using oracle

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900