订单ID从每天0开始 [英] Order ID to start from 0 everyday

查看:85
本文介绍了订单ID从每天0开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个订单表,我在其中使用带有标识的order_id字段。



我希望每隔一天从1开始order_id。是否有可能。





order_id day

1 sunday

2 sunday

3周日

1星期一

2星期一

3星期一

4星期一

1星期二

2 tuseday

3星期二

4星期二

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

推荐答案

不是。你在谈论的是一个复合键,其中行的唯一性由''order id,day'组成。



在这样的表格中,你应该总是有一个基于IDENTITY的递增唯一ID,这应该是你的主键。然后,您可以拥有符合您需要的后续字段,但您必须自己管理ID生成。



保存自己的工作和未来的头痛 - 让订单ID成为一个身份字段,每天从零开始,你引入复杂性,你什么都得不到。
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.


我知道它会产生复杂性但是可以使用sql。

如果我有三列其中id是带有身份而orderno是通过连接ddMyyy和id创建的



但是每隔一天我想要id从1开始...

所以,订单ID今天看起来像230520131 。

明天它应该从240520131开始
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


这篇关于订单ID从每天0开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆