I am using sql server 2008. Is there a way to generate a unique serial number? It should demonstrate the properties of NEWID () and the identity column, which means that it is always unique, but each subsequent value is larger than the previous one. It cannot be datetime / datetime2 because it is not unique enough.
Thanks.
A data type ROWVERSIONis one possibility, although it is not suitable for use as a primary key; It is also automatically installed.
ROWVERSION
- . , . , .
- CLR SQL. , . , , , . , , , .
CREATE TABLE demo_table ( demo_id uniqueidentifier NOT NULL, demo_value int ); ALTER TABLE demo_table ADD CONSTRAINT dc_demo DEFAULT NEWSEQUENTIALID() FOR demo_id;
.
, NEWSEQUENTIALID() , .
NEWSEQUENTIALID()
NEWSEQUENTIALID() , B-, . :
NEWID(), NEWSEQUENTIALID() IDENTITY: " : - ( ) x NewId() x NewSequentialId".
NEWID()
IDENTITY
. NEWSEQUENTIALID .
, . .
Given that both IDENTITY and NEWSEQUENTIALID should only be internal (e.g. not human readable), why is this a requirement?
You can define the newsequentialid()default value for a UNIQUEIDETIFIER column in SQL Server 2008 - unfortunately, all that you can do.
newsequentialid()
CREATE TABLE dbo.MyTable ( ID UNIQUEIDENTIFIER DEFAULT (newsequentialid()) ...... )
There is no way to generate a sequential identifier (GUID) in any other way: - (
Source: https://habr.com/ru/post/1725469/More articles:Metamorphic generator - assemblypopViewControllerAnimated does not update iPhone SDK information - iosBackpropagation Problems - artificial-intelligence2s в- htmlPost fancebox ajax in iframe - javascriptИспользование выпуска SQL Express в коммерческих целях - sql-server-2008Hibernate Large Class Breakdown - hibernateto clear weird ruby encoding - jsonHow can a generic event handler find out which control event it is handling? - objectWhy does fsutil.exe take less time to write a huge file to disk than programmatically? - windowsAll Articles