Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 To create a uniqueidentifier data type and...

Author  Topic 

cesark
Posting Yak Master

215 Posts

Posted - 2003-09-15 : 11:21:08
Hi!
I want to create a uniqueidentifier data type in a existing table but i can't. I write the syntax as follows:

ALTER TABLE Users
ALTER COLUMN User_Id (uniqueidentifier NOT NULL DEFAULT NEWID())

What is wrong?

Another question is; I use a stored procedure to do new inserts in a table and to write the same generated identity to other tables which needed. This sp use a variable to store the newid generated retrived by the @@Identity (SELECT @NewId=@@Identity). What function is it better to retrieve the last identity and to ensure that is the real last generated? @@Identity, SCOPE_IDENTITY or IDENT_CURRENT. Which is the difference between these?.
In my application will have many users at the same time inserting data and they will not still be registered.

Cesar

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2003-09-15 : 11:30:16
I suspect the problem is your default value NEWID().....which may not match your column data-type.

try
ALTER TABLE Users
ALTER COLUMN User_Id (uniqueidentifier)
on an empty USERS table....

if this works....it's the default value that is giving you a problem.
Go to Top of Page

cesark
Posting Yak Master

215 Posts

Posted - 2003-09-15 : 12:14:39
Good! The problem was solved.

What about my last doubt:

I use a stored procedure to do new inserts in a table and to write the same generated identity to other tables which needed. This sp use a variable to store the newid generated retrived by the @@Identity (SELECT @NewId=@@Identity). What function is it better to retrieve the last identity and to ensure that is the real last generated? @@Identity, SCOPE_IDENTITY or IDENT_CURRENT. Which is the difference between these?.
In my application will have many users at the same time inserting data and they will not still be registered.

Thanks,
Cesar

Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2003-09-17 : 06:59:52
forum search for SCOPE_IDENTITY,IDENT_CURRENT (either word OPTION) and several topics can be examined in which this has come up before....IDENT_CURRENT seems to be related to SQL2K.

one of the topics is...http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=21283

also BOL is pointed to as a information source in explaining this.

having multiple users all running the same SP at the same time, will give independant results to each user....there should be no cross contamination of data.



this link (http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=29208) gives a detailed explaination of the reason for using SCOPE_IDENTITY v @@IDENTITY
Go to Top of Page

jeffreymfischer
Starting Member

10 Posts

Posted - 2009-10-07 : 11:19:48
I've written a detailed article on an enterprise-ready unique identifier solution.

http://blog.scoftware.com/post/2009/08/29/SQL-Server-UniqueIdentifier-Globally-Unique-Globally-Sequential-SOLUTION.aspx

Read it and provide feedback.

Jeff Fischer

Scoftware Achitect/Developer
http://blog.scoftware.com

Scoftware Achitect/Developer
http://blog.scoftware.com
Go to Top of Page
   

- Advertisement -