Hello All,
I am using SQL server 2008.
I have a window service which is used to insert / update records in a table.
I am calling the stored procedure for each record.
My table has a column named ID [uniqueidentifier] and my stored procedure is like something like this. This ID should remain same for the updated records and for a new record I am generaing a newid.
CREATE Proc NAME_XXXXXXX
(
@P1 nvarchar(255),
@P2 nvarchar(255),
@P3 nvarchar(255),
@P4 nvarchar(255)=null,
@P5 nvarchar(50)=null,
@P6 nvarchar(50)=null,
@P7 nvarchar(50)=null,
@P8 nvarchar(50)=null,
@P9 int=null,
@P10 nvarchar(50)=null
)
as
Begin
if EXISTS( Select top 1 1 from TABLE_XYZ Where P1=@P1 and P3=@P3)
Begin
update TABLE_XYZ
set
P2=@P2
,P4=@P4
,P5=@P5
,P10=@P10
,P6=@P6
,P7=@P7
,P8=@P8
,P9=@P9
Where P1=@P1 and P3=@P3
End
Else
Begin
insert into TABLE_XYZ(ID,P1,P2,P4,P3,P5,P10,P6,P7,P8,P9)
values(newid(),@P1,@P2,@P4,@P3,@P5,@P10,@P6,@P7,@P8,@P9)
End
End
How can I improve the performance.
Thanks,
Debata