Need tips to optimize SQL Server stored procedure -


this stored procedure, it's taking time execute though running local database.

please suggest changes in order improve performance

begin try         declare @country_cd int         set @country_cd =(select country_cd country country_desc = ltrim(rtrim(@country_desc)))         declare @companny_cd int         set @companny_cd =(select company_cd company company_desc = ltrim(rtrim(@company_desc)))     begin transaction         delete pack            country_cd = @country_cd                  , company_cd = @companny_cd                 , pack_desc = ltrim(rtrim(@pack_desc))     commit transaction end try begin catch     if(@@trancount > 0)         rollback transaction     declare @errmsg nvarchar(4000),              @errseverity int     select @errmsg = error_message(),@errseverity = error_severity()     raiserror(@errmsg, @errseverity, 1) end catch 

hard without knowing more database schema. few initial ideas might cleanup *_desc variables right away rather doing ltrim , rtrim in clause. maybe consider or add index on pack table includes country_cd/company_cd (not description though, assuming it's long string text. think company , country pretty small tables, have proper indexes on fields. might worth trying join tables in delete rather doing lookups ahead of time.

-- clenaup variables -- these should new vars, not input parms select @country_desc = ltrim(rtrim(@country_desc))     ,@company_desc = ltrim(rtrim(@company_desc))     ,pack_desc = ltrim(rtrim(@pack_desc ))  -- delete    delete pack pack join country on pack.country_cd = country.country_cd join company on pack.company_cd = company.company_cd   country.country_desc = @country_desc  , company.company_desc = @company_desc , pack.pack_desc = @pack_desc 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -