Output of generated keys not working for UUID / uniqueidentifier
See original GitHub issueI am using UUID
/ uniqueidentifier
primary keys.
CREATE TABLE test (
id UNIQUEIDENTIFIER DEFAULT NEWID(),
text VARCHAR(255)
)
When inserting a new object, I dont get the generated id. GENERATED_KEYS
is empty.
INSERT INTO test (text) VALUES('test') select SCOPE_IDENTITY() AS GENERATED_KEYS;
Will return NULL
.
That is an issue of SQL Server but the workaround would be to use the OUTPUT
syntax:
INSERT INTO test (text) OUTPUT inserted.id VALUES('test');
That will actually return something like | id | B5BA707B-872E-4BFC-8A96-97A1D789E74C |
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Problem obtaining entities with uniqueidentifier primary key
I had the same problem and I solved it by adding uuid-char type to column.
Read more >Auto generated SQL Server keys with the uniqueidentifier or ...
Another way to auto-generate key values is to specify your column as a type of uniqueidentifier and DEFAULT using NEWID() or NEWSEQUENTIALID().
Read more >UUID or GUID as Primary Keys? Be Careful! | by Tom Harrison
Databases support integer primary keys and they are fast and elegant. ... Another problem is fragmentation — because UUIDs are random, ...
Read more >The best UUID type for a database Primary Key - Vlad Mihalcea
In this article, we are going to see what UUID (Universally Unique Identifier) type works best for a database column that has a...
Read more >Understanding the GUID data type in SQL Server
Let's see what issues we face if we have redundant records within ... is also the primary key column for the newly created...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Whatever works with custom statements,
r2dbc-mssql
doesn’t return ids withspring-data-r2dbc
where other drivers do.We switched to
r2dbc-postgresql
for that reason and everything works fine.Thanks, I missed that subtlety.