Home

Awesome

TypeId T-SQL (SQL Server)

TypeId implementation in pure T-SQL.

Install / Generate

Directly run the content of typeid_tsql on your server.

Regenerate the SQL by yourself using the script ./build.sh

Usage

CREATE TABLE MyTable (
    Id VARCHAR(90) NOT NULL DEFAULT dbo.typeId_NewTypeId('test'),
    Label VARCHAR(100)
)
GO

INSERT INTO MyTable (Label) VALUES ('new label')
GO

SELECT Id, Label, dbo.typeId_Decode(Id) AS DecodedUID FROM MyTable
GO
IdLabelDecodedUID
test_069t2trynchwpq50001pqtwnpynew label064e85ac-7aac-8f2d-7280-000dafae56de

Caveat

It's not possible to generate a sub-millisecond timestamp in T-SQL. Thus, we generated the timestamp using a millisecond unix timestamp combined with random data. That means that two typeid generated in the same millisecond won't be k-sortable.

I believe that it would be possible to combine the timestamp with a number coming from a Sequence to preserve the sequentiality and concurrency.