Joe,
The stored procedure was written years ago by someone
who is long gone. I inherited it.
For new stored procedures we now know to prefix them with
something other than "sp_"
I know what a transaction is, I am trying to understand what
"serializable isolation level" is.
Someone suggested that I do this:
begin tran
Select @newRegNum = (Select min(Reg) from reg_number with
updlock,rowlock)
I am not sure about how to configure the transaction,
As this stored procedure is being called from another
stored procedure, at a point in the calling stored procedure
when another transaction is active.
Thank You,
Laurence Nuttall
Programmer Analyst III
UCLA - Division of Continuing Education
'-------------------------------
Here is the DDL for the table:
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[Reg_Number]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Reg_Number]
GO
CREATE TABLE [dbo].[Reg_Number] (
[Reg_Number_ID] [int] NOT NULL ,
[Reg] [char] (6) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Login] [char] (8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Modified_date] [smalldatetime] NULL ,
[Concurrent_use] [tinyint] NULL
) ON [PRIMARY]
GO
'---------------------------------------------------------------------------------------------------------------
[quoted text, click to view] Joe Celko wrote:
> The trick is to use a transaction and a serializable isolation level.
>
> That is the first code I have seen with GOTO statements in over 15
> years! Did you mean to put a "sp_" prefix on the code?
>
> Could I suggest that instead of deleting the reg numbers as they are
> issued, that you update the table to show the date and time they are
> issued? No sense losing information and the ability to re-construct a
> history. Might want to add the user info, too. Something like this:
>
> CREATE PROCEDURE GetNextRegnum
> @newregnum CHAR(6) OUTPUT
> AS
> BEGIN TRANS
> SET @newregnum
> =(SELECT MIN(reg)
> FROM RegNumbers
> WHERE issue_date IS NULL);
> UPDATE RegNumbers
> SET issue_date = CURRENT_TIMESTAMP
> WHERE reg = @newregnum;
> << error handling, commit, rollback here >>
> END;
>
> --CELKO--
> ===========================
> Please post DDL, so that people do not have to guess what the keys,
> constraints, Declarative Referential Integrity, datatypes, etc. in your
> schema are.
>
> *** Sent via Devdex
http://www.devdex.com ***
The trick is to use a transaction and a serializable isolation level.
That is the first code I have seen with GOTO statements in over 15
years! Did you mean to put a "sp_" prefix on the code?
Could I suggest that instead of deleting the reg numbers as they are
issued, that you update the table to show the date and time they are
issued? No sense losing information and the ability to re-construct a
history. Might want to add the user info, too. Something like this:
CREATE PROCEDURE GetNextRegnum
@newregnum CHAR(6) OUTPUT
AS
BEGIN TRANS
SET @newregnum
=(SELECT MIN(reg)
FROM RegNumbers
WHERE issue_date IS NULL);
UPDATE RegNumbers
SET issue_date = CURRENT_TIMESTAMP
WHERE reg = @newregnum;
<< error handling, commit, rollback here >>
END;
--CELKO--
===========================
Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are.
*** Sent via Devdex
http://www.devdex.com ***