如何自动递增8位参考编号? [英] How do I auto increment an 8-digit reference number?

查看:87
本文介绍了如何自动递增8位参考编号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



一个新手问题。



让我们说我需要创建一个名为'Cars'的数据库,我想'自动递增''CarId'列。



我将对此特定列使用以下语句:

Hello,

A newbie question.

Lets say I need to create a database called 'Cars' and I want to 'auto increment' the 'CarId' column.

I would use the following statement for this particular column:

CarId int IDENTITY(1,1) Primary Key 





每次将新记录插入数据库时​​,都会添加一个数字CarId为1,2,3,4等等。



如果我想分配一个随机的8位'CarId'号或8位数的订单怎么办? 'CarId'号码,最好的方式是什么?



请有人建议。



谢谢



我的尝试:



我正在学习使用SQL Server 2012 Express



Every time a new record is inserted into the database it would add a number to the CarId as 1, 2, 3, 4 and so on.

What if I wanted to allocate a random 8 digit 'CarId' number or an ordered 8-digit 'CarId' number, what would be the best way of going about this?

Please can someone advise.

Thanks

What I have tried:

I'm learning to work with SQL Server 2012 Express

推荐答案

随机是一个坏主意:它们发生冲突太常见了。如果您想要随机ID,那么请使用UNIQUEIDENTIFIER,但它们绝对不是8位数!



订单是您从IDENTITY获得的,并且整数总是潜在的8位数(只是它们从7开始或者它们具有前导零。

获得真正的8位序列的一种方法是将列定义为

Random is a bad idea: they clash far too often. If you want "random ids" then use UNIQUEIDENTIFIER instead, but they are most definitely not 8 digit!

Orders is what you get from IDENTITY, and integers are always potentially 8 digit (just they start with 7 or them having leading zeros.
One way to get a "true" 8 bit sequence is to define your column as
CarID INT IDENTITY(10000000, 1) PRIMARY KEY

这意味着他们从10,000,000开始并从那里上升。

Which means they start from 10,000,000 and go up from there.


这篇关于如何自动递增8位参考编号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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