Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Stored Proc

Author  Topic 

cipriani1984
Constraint Violating Yak Guru

304 Posts

Posted - 2011-09-23 : 05:00:30
Hi,

I have the following stored proc which is taking quite long time to execute and looking for a way to optimize it.

Create proc

Check table exists,
else create table

insert records into temp table

insert into table above temp table the differences/new records

-------------

The problem or wierdest thing im having is that when I run the code seperately from the stored procedure it runs quite alot faster than when I run 'exec sp etc...'

a little education would be much appreciated!

thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-23 : 05:23:02
are you using parameters in sp?
what will be amount of records that will get inserted to temp table?
Are you creating proper indexes in it
DId you check execution plan and see which step takes maximum cost?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

cipriani1984
Constraint Violating Yak Guru

304 Posts

Posted - 2011-09-23 : 05:42:47
There are no parameters and no dynamic sql.

The temp table probably loaded around half a mill to 1.2 mill records depending on where i look at.

But not using any indexing, can you advise?

quote:
Originally posted by visakh16

are you using parameters in sp?
what will be amount of records that will get inserted to temp table?
Are you creating proper indexes in it
DId you check execution plan and see which step takes maximum cost?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-23 : 05:46:27
check execution plan and see costly steps first.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2011-09-23 : 06:52:59
Post the code for us to have a look at please
Go to Top of Page
   

- Advertisement -