在SQL中递增VarChar值 [英] Increment VarChar Value in SQL

查看:107
本文介绍了在SQL中递增VarChar值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有SQL表,我的PK列为

I have SQL table ,my PK col is

Job_Code Varchar(50)



PK col值是这样的

J001
J002
J003
......

我想用1增加我的PK col.

如何执行此操作可以帮助我执行此操作.


谢谢你,



PK col values are like this

J001
J002
J003
......

I want to increment my PK col with 1.

How to do this can any one help me to do this.


Thank u ,

推荐答案

您可以遵循这种方法
you can follow this approach
http://stackoverflow.com/questions/4699591/how-to-autoincrement-varchar[^]


在我看来,不要这样做.切勿将两个单独的值连接到单个列中.如果您需要一个描述性的列(如"J"),则将其单独添加到表中.

但是,如果J是一个常量,我会说您根本不需要它.只需坚持定义一个工作的唯一编号即可.

还要注意,永远不要依赖唯一键的顺序,也不要包含任何空洞.密钥是密钥,其目的是使用户能够快速访问行.如果要对行进行排序,排序等,则应由查询完成,并且不应将其保留在数据库中.这样做的理由是,您基本上只能存储一个订单,并且您的应用程序中可能需要几个不同的订单.同样,如果在数据库和/或应用程序中没有大量额外的逻辑,就无法保证值中没有漏洞.
In my opinion, don''t do this. Never concatenate two separate values into a single column. If you need to have a describing column (like the ''J'') then add it separately to the table.

However, if the J is a constant I''d say you don''t need it at all. Just stick to the unique number defining a single job.

Also note that never ever rely on the order of the unique keys nor that they would contain no holes. A key is a key and it''s purpose is to give a quick access to a row. If you want to order, rank etc the rows, that should be done by a query and it shouldn''t be persisted in the database. The justification for this is that you can basically store just one order and you may need several different orders in your application. Also you cannot quarantee that there is no holes in the values without extensive amount of extra logic in your database and/or in your application.


这篇关于在SQL中递增VarChar值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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