Sequential NEWID ()

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.

+3
source share
4 answers

A data type ROWVERSIONis one possibility, although it is not suitable for use as a primary key; It is also automatically installed.

- . , . , .

- CLR SQL. , . , , , . , , , .

+1
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() , B-, . :

NEWID(), NEWSEQUENTIALID() IDENTITY: " : - ( ) x NewId() x NewSequentialId".

+7

. NEWSEQUENTIALID .

, . .

Given that both IDENTITY and NEWSEQUENTIALID should only be internal (e.g. not human readable), why is this a requirement?

+2
source

You can define the newsequentialid()default value for a UNIQUEIDETIFIER column in SQL Server 2008 - unfortunately, all that you can do.

CREATE TABLE dbo.MyTable
(
    ID UNIQUEIDENTIFIER DEFAULT (newsequentialid())
    ......
)

There is no way to generate a sequential identifier (GUID) in any other way: - (

+1
source

Source: https://habr.com/ru/post/1725469/


All Articles