Click here to Skip to main content
15,879,474 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a order table where i am using order_id field with identity.

i want to start order_id from 1 on every next day. is it possible.


order_id day
1 sunday
2 sunday
3 sunday
1 monday
2 monday
3 monday
4 monday
1 tuesday
2 tuseday
3 tuesday
4 tuesday
Posted
Comments
gvprabu 23-May-13 4:26am    
If u will give Identity Property then u can't able to set Duplicate values... so better use one varchar field and do this through SP.

Not really. What you are talking about is a compound key, where the uniqueness of the row is made up of 'order id, day'

In a table such as this, you should always have an incrementing unique id that is based on IDENTITY, this should be your primary key. You can then have subsequent fields that do what you want, but you'd have to manage the ID generation yourself.

Save yourself work and a future headache - let order id just be an Identity field, you gain nothing by having it start from zero each day and you introduce complexity.
 
Share this answer
 
i know it will create complexity but is it possible using sql.
if i have three columns where id is with identity and orderno is created by concatenating ddMyyy and id

but at every next day i want id to start with 1...
so, the order id will look like 230520131 for today.
and for tomorrow it should start with 240520131
 
Share this answer
 
Comments
MuhammadUSman1 23-May-13 7:30am    
Are You inserting Values using any Application?

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