是否有像IDENTITY列类型的TSQL字母数字?

时间:2022-08-04 09:26:50

Is there an IDENTITY like column type that generates alphanumeric values? Like 023904F?

是否有类似IDENTITY的列类型生成字母数字值?喜欢023904F?

3 个解决方案

#1


3  

YES, the uniqueidentifier column, but it is 36 chars in length, try this:

是,uniqueidentifier列,但它的长度为36个字符,试试这个:

select newid()

output

产量

------------------------------------
53F2103C-C357-429E-A0E8-2DC26666638F

(1 row(s) affected)

you can use it like:

你可以使用它:

select LEFT(newid(),7)

and get:

得到:

-------
50D0F58

(1 row(s) affected)

this will not be unique though.

但这并不是唯一的。

#2


2  

No: you have to write a function to do it for you. Or concatenate "F" to a number in a computed columns

不:你必须写一个功能来为你做。或者将“F”连接到计算列中的数字

previous questions:

以前的问题:

SQLServer IDENTITY Column with text

带有文本的SQLServer IDENTITY列

Increasing Alphanumeric value in user defined function

增加用户定义函数中的字母数字值

#3


0  

No - but you could always

不 - 但你可以永远

  • create an INT IDENTITY column
  • 创建INT IDENTITY列
  • add a computed column such as

    添加一个计算列,如

    ALTER TABLE dbo.YourTable 
       ADD ProductID AS CAST(ID AS VARCHAR(8)) + 'F'
    

    or whatever it is you want to do to the ID to make it into your alphanumeric field

    或者你想对ID做什么,使其成为你的字母数字字段

#1


3  

YES, the uniqueidentifier column, but it is 36 chars in length, try this:

是,uniqueidentifier列,但它的长度为36个字符,试试这个:

select newid()

output

产量

------------------------------------
53F2103C-C357-429E-A0E8-2DC26666638F

(1 row(s) affected)

you can use it like:

你可以使用它:

select LEFT(newid(),7)

and get:

得到:

-------
50D0F58

(1 row(s) affected)

this will not be unique though.

但这并不是唯一的。

#2


2  

No: you have to write a function to do it for you. Or concatenate "F" to a number in a computed columns

不:你必须写一个功能来为你做。或者将“F”连接到计算列中的数字

previous questions:

以前的问题:

SQLServer IDENTITY Column with text

带有文本的SQLServer IDENTITY列

Increasing Alphanumeric value in user defined function

增加用户定义函数中的字母数字值

#3


0  

No - but you could always

不 - 但你可以永远

  • create an INT IDENTITY column
  • 创建INT IDENTITY列
  • add a computed column such as

    添加一个计算列,如

    ALTER TABLE dbo.YourTable 
       ADD ProductID AS CAST(ID AS VARCHAR(8)) + 'F'
    

    or whatever it is you want to do to the ID to make it into your alphanumeric field

    或者你想对ID做什么,使其成为你的字母数字字段