NEWSEQUENTIALID() is broken in SQL Server for linux?

女生的网名这么多〃 提交于 2019-12-07 16:49:56

问题


I am running MS SQL Server for linux from a Docker image (https://hub.docker.com/r/microsoft/mssql-server-linux/)

I've discovered in my log files, that there are many PRIMARY KEY violations on my log table, which has ID uniqueidentifier DEFAULT NEWSEQUENTIALID() column.

Exception is:

Exception: System.Data.SqlClient.SqlException: 
Violation of PRIMARY KEY constraint 'PK_Logs'. 
Cannot insert duplicate key in object 'dbo.Logs'. 
The duplicate key value is (20c0423e-f36b-1410-8020-800000000000).

As stated in documentation

NEWSEQUENTIALID is a wrapper over the Windows UuidCreateSequential function.

(source: https://docs.microsoft.com/en-us/sql/t-sql/functions/newsequentialid-transact-sql)

How does it work on linux then? Is the behaviour broken, since generated GUIDs should be unique, and they are clearly not.

Reproduction steps

  1. start mssql-server-linux docker image docker run mssql-server-linux (refer to https://hub.docker.com/r/microsoft/mssql-server-linux/ for details)

  2. Create table CREATE TABLE SequentialIdTest(ID uniqueidentifier PRIMARY KEY DEFAULT NEWSEQUENTIALID(), ColA int );

  3. Insert new row INSERT INTO SequentialIdTest(ColA) VALUES (0);

  4. restart docker image docker restart {CONTAINER_NAME}

  5. Try to insert new row again INSERT INTO SequentialIdTest(ColA) VALUES (0);

来源:https://stackoverflow.com/questions/44649830/newsequentialid-is-broken-in-sql-server-for-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!