snippetsqlMinor
How to make a unique column with default value of UUID
Viewed 0 times
uniquecolumnwithmakevaluedefaulthowuuid
Problem
I have a key column for internal use which is just a increasing integer, but I would like to have a second unique column which is a UUID, but I don't know how to have a function called for the default value (so that SQL Server is creating the UUID and not java), is there any documentation that one could suggest to me for this?
Solution
Not sure if I'm understanding your question correctly, but you can have a
Does that fulfill your requirements?
uniqueidentifier field in your table. If you want to generate a uid for a record you can do something like this:create table UniqueIdTest
(
someint int not null,
someid uniqueidentifier not null
)
insert into UniqueIdTest(someint, someid)
values(1, NEWID())Does that fulfill your requirements?
Code Snippets
create table UniqueIdTest
(
someint int not null,
someid uniqueidentifier not null
)
insert into UniqueIdTest(someint, someid)
values(1, NEWID())Context
StackExchange Database Administrators Q#6840, answer score: 6
Revisions (0)
No revisions yet.