calorisplanitia
asked on
Best way to generate userid(integer value), should i use identity column or something else? Please advise
I have a login table which generates users and generates an id for the user. I am not sure whether to use IDENTITY_Column(autonumber ) so that sql server generates a unique id by itself or use something else.
Some people advised me using identity specification lock table and causes performance issues.
At present i am using the following:
I want to know the right approach as i need to use these for chat applications in msgs tables also where lots of records are inserted at a time by many users.
Please advise
Thanks in advance.
Some people advised me using identity specification lock table and causes performance issues.
At present i am using the following:
SET NOCOUNT ON;
DECLARE @intErrorCode INT
BEGIN TRANSACTION
SET @TID=(select (counterfrom + currentcounter) from e_counter
SELECT @intErrorCode = @@ERROR
IF (@intErrorCode <> 0) GOTO PROBLEM
insert into e_Login
(id,Username,Password) values
(@TID, 'U-','U-')
SELECT @intErrorCode = @@ERROR
IF (@intErrorCode <> 0) GOTO PROBLEM
UPDATE e_counter set currentcounter=(currentcounter + 1) where functionno=@FUNID
SELECT @intErrorCode = @@ERROR
IF (@intErrorCode <> 0) GOTO PROBLEM
COMMIT TRANSACTION
PROBLEM:
IF (@intErrorCode <> 0)
BEGIN
ROLLBACK TRAN
SET @TID=0
END
I want to know the right approach as i need to use these for chat applications in msgs tables also where lots of records are inserted at a time by many users.
Please advise
Thanks in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
will the table be available for view when the records are inserted, while using identity?
Even in such a case, an Identity column will still perform better than generating your own unique id
It is even more better to use identity if you have hundreds of message inserted at a time. The table will be available for view since inserting is not locking existing rows.
Hi,
You have to use the identity column and also use this column with the concatenation with the userid + identity column and store it into any varchar type datafield and also define as unique value.
You have to use the identity column and also use this column with the concatenation with the userid + identity column and store it into any varchar type datafield and also define as unique value.
ASKER
Apologies, i forgot to mark this question as completed.
I tested myself also and found that identity coulmns are much better.
Thanx to you all for helping me out.!
I tested myself also and found that identity coulmns are much better.
Thanx to you all for helping me out.!
ASKER