August 3, 2004 at 4:24 am
Are there any big disadvantages with what i've done here for generating id's ?
Table with 3 cols:
CREATE TABLE [dbo].[IdGenerator] (
[TtypeId] [int] NOT NULL ,
[TypeDescription] [varchar] (50) NOT NULL ,
[NextId] [int] NOT NULL
The use an sp to get the next id:
CREATE PROCEDURE dbo.GenerateId
(@TypeId int,
@Id int OUTPUT)
AS
BEGIN
BEGIN TRANSACTION GetId
SELECT@Id = NextId
FROMIdGenerator
WHERETypeId = @TypeId
UPDATE IdGenerator
SETNextId = @Id + 1
WHERETypeId = @TypeId
COMMIT TRANSACTION GetId
RETURN @Id
END
GO
I understand it may be a little slow for large systems as there will be waits but the system i use will not be very busy so it there any other disadvantages?
Viewing post 16 (of 15 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy