9

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?

12
CREATE TABLE TblUID
(
    ID INT NOT NULL,
    UID UNIQUEIDENTIFIER NOT NULL DEFAULT NEWID()
)
1
6

Not sure if I'm understanding your question correctly, but you can have a 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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.