如何在sql中以增量插入4位数字 [英] how to insert 4 digits numeric in sql with increment
本文介绍了如何在sql中以增量插入4位数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我想在我的sql表中插入4或5位数字值。
我应该使用哪种数据类型必须要n我怎么能插入它。
我怎样才能增加这个值。
这个值是注册号。
Hi guys,
I want to insert 4 or 5 digits numeric value in my sql table.
what data type should i have to take n how can i insert it.
and how can i increment this value.
this value is for registration number.
eg:
0001
0002
0003
0004
.
.
.
0010
.
.
0100
.
.
起始值应为0001并隐式增加代码。
请帮帮我。
谢谢
starting value should be 0001 and implicitly increment it by code.
Please help me.
Thanks
推荐答案
你可以用身份 [ ^ ]列。
Eg
You can use an identity[^] column.
E.g.
reg_num int IDENTITY(1000,1),
对于插入的每个新行,数字将自动递增。
编辑 - 可以在此帖的解决方案中找到替代方案(不推荐)如何在sql中自动生成EMPID? [ ^ ]
您可以在SQL Server中使用IDENTITY列,在Oracle中使用SEQUENCE。它会自动增加其值,也可以设置起始值。
谢谢
Hi,
You can use IDENTITY column in SQL Server or SEQUENCE in Oracle .It will automatically increment its value and also you can set the starting value.
Thanks
SELECT'RAK'+ right('0000'+ convert(varchar(10),Suffix), 5)AS'Ticke t'来自tbl_Tickets
//'后缀'是列名
SELECT 'RAK' + right('0000' + convert(varchar(10), Suffix), 5) AS 'Ticket' from tbl_Tickets
//'Suffix' is a column name
这篇关于如何在sql中以增量插入4位数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文