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
 Transact-SQL (2000)
 get unique id

Author  Topic 

sasan_vm
Yak Posting Veteran

51 Posts

Posted - 2011-05-07 : 11:25:26
Hello,

In client/server application with many clients, can this code guaranty any client on request new id get unique id ?

Kind Regards,
sasan.



/*
CREATE TABLE [tbl_uniqe_id] (
[ID] [bigint] IDENTITY (1, 1) NOT NULL ,
[ClientID] [bigint] NOT NULL ,
CONSTRAINT [PK_tbl_uniqe_id] PRIMARY KEY CLUSTERED
(
[ID]
) ON [PRIMARY]
) ON [PRIMARY]
*/

CREATE PROC pr_getUID
@ClientID bigint
AS
BEGIN
DECLARE @uID bigint,
@erCode int

SET NOCOUNT ON
INSERT tbl_uniqe_id (ClientID) VALUES (@ClientID)
SELECT @erCode = @@error, @uID = @@identity
IF @erCode <> 0
BEGIN
RAISERROR('Unable to get new id:', 16, 1)
RETURN @erCode
END

RETURN @uID
END

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-05-07 : 11:32:08
Should be ok as long as there's no trigger on the table - might want to us scope_identity() instead of @@identity if that is available in v2000.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -