Saklı yordamdan C# rutinine, tek bir skaler değeri döndüren üç farklı yöntemden birini kullanmanın olası performans etkisini tartıyorum. Kimse bunlardan hangisinin "daha hızlı" ve en önemlisi neden olduğunu söyleyebilir mi?SQL Server Performans SonuçSet vs Çıkış Parametresi vs Dönüş Değeri
Yöntem 1:
CREATE PROCEDURE GetClientId
@DealerCode varchar(10)
AS
BEGIN
SET NOCOUNT ON
SELECT ClientId
FROM Client
WHERE ClientCode = @DealerCode
END
-- this returns null if nothing is found,
-- otherwise it returns ClientId in a ResultSet
Yöntem 2:
CREATE PROCEDURE GetClientId
@DealerCode varchar(10),
@ClientValue int out
AS
BEGIN
SET NOCOUNT ON
set @ClientValue = -1
set @ClientValue = (SELECT ClientId
FROM Client
WHERE ClientCode = @DealerCode)
END
-- this returns -1 for ClientValue if nothing is found,
-- otherwise it returns ClientId
-- the value for ClientValue is a scalar value and not a ResultSet
Yöntem 3:
CREATE PROCEDURE GetClientId
@DealerCode varchar(10)
AS
BEGIN
SET NOCOUNT ON
declare @ClientValue int
set @ClientValue =
(SELECT ClientId FROM Client WHERE ClientCode = @DealerCode)
if @ClientValue is null or @ClientValue = 0
return -1
else
return @ClientValue
END
-- this uses the return value of the stored procedure;
-- -1 indicates nothing found
-- any positive, non-zero value is the actual ClientId that was located
Başka bir hassasiyet. Yöntem 3 (RETURN) ile, INTEGER tipi ile sınırlıdır. Başka bir veri türü döndürmek isterseniz, Yöntem 2'yi veya Yöntem 1'i kullanmalısınız. –
Tüm yardımı takdir ediyorum. Şahsen 2'ye doğru eğildim. Ancak, # 2 ve # 3'te INTEGER döndürdüğümde # 3'ün en iyi performansa sahip olacağını görebiliyordum. Bir tür dize döndürmek zorunda kalırsam # 2 kullanırdım. Tabii, önceden belirtildiği gibi, sadece bir sonuç kümesine ihtiyacım varsa # 1 kullanırdım. –