Is there an IDENTITY like column type that generates alphanumeric values? Like 023904F?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
YES, the uniqueidentifier column, but it is 36 chars in length, try this:
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:
No: you have to write a function to do it for you. Or concatenate "F" to a number in a computed columns
previous questions:
SQLServer IDENTITY Column with text
Increasing Alphanumeric value in user defined function
回答3:
No - but you could always
- create an INT IDENTITY column
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