问题
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
start mssql-server-linux docker image
docker run mssql-server-linux
(refer to https://hub.docker.com/r/microsoft/mssql-server-linux/ for details)Create table
CREATE TABLE SequentialIdTest(ID uniqueidentifier PRIMARY KEY DEFAULT NEWSEQUENTIALID(), ColA int );
Insert new row
INSERT INTO SequentialIdTest(ColA) VALUES (0);
restart docker image
docker restart {CONTAINER_NAME}
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