Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 7 down vote accepted
CREATE TABLE TblUID
(
    ID INT NOT NULL,
    UID UNIQUEIDENTIFIER NOT NULL DEFAULT NEWID()
)
share|improve this answer
3  
That, or NEWSEQUENTIALID(). –  Nick Chammas Oct 15 '11 at 2:56
add comment

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?

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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