Here are the needed Informations:
CREATE TABLE [dbo].[Codes](
[Code] [char](10) NOT NULL,
CONSTRAINT [PK_Codes] PRIMARY KEY CLUSTERED
(
[Code] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
-------------------------------------------------------------------------------------------------
THE STORED PROCEDURE
ALTER PROCEDURE [dbo].[CreateCodes]
-- Add the parameters for the stored procedure here
@amount bigint
AS
BEGIN
SET NOCOUNT ON
declare @tempcode as nvarchar(100)
declare @counter as bigint
set @counter = 1
while @counter <= @amount
begin
set @tempcode = (SELECT [dbo].[RNGCharacterMask] (8 ,'34679CDFGHJKLNPRTVXY') )
if ((select count(code) from codes where code = @tempcode) = 0)
begin
insert into codes (code) values (@tempcode)
set @counter = @counter + 1
continue
end
else
continue
end
set nocount off
END
-----------------------------------------------------------------------------------------------
The Stored Procedure calls a User defined function which generates the codes. But this ist not
the reason why the performance ist so bad.
In addition I add the excecution plan as txt file. and I think the most performance is consumed by the insert statement. But take a look and give me your feedbacks.