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.
Author |
Topic |
ranjeetsingh_6
Posting Yak Master
125 Posts |
Posted - 2007-04-12 : 07:44:14
|
HiI have write a store procedure given below execute fine but take more time(30 second).In This i do two task1:-If a table exists then Drop It.2:-next i copy a Table's records into another table.Note:-In procedure Dynamic sql query used because Table name come fromparameter.Give me some sugession to increase speed.procedure is:----------------------------------------------------------------------create procedure record@user_id varchar(20)=null,@frtime varchar(100)=null,@totime varchar(100)=nullasset nocount ondeclare @yes varchar(10),@query nvarchar(4000)set @yes='yes'IF OBJECT_ID(@user_id) IS NOT NULL begindeclare @qrydroptable nvarchar(100)set @qrydroptable='DROP table ' + @user_idexec(@qrydroptable)endselect @query='select distinct tempaddplace.* into'+' '+ @user_id +' '+ ' from JOURNEY_REGT_DET inner join assign_vehicle_access on JOURNEY_REGT_DET.vehicle_id=assign_vehicle_access.vehicle_id inner join tempaddplace on tempaddplace.Jrid=JOURNEY_REGT_DET.JOURNEY_ID where assign_vehicle_access.Assign='''+@yes+''' andtempaddplace.Timerecorded >=convert(datetime,'''+@frtime+''',103) and tempaddplace.Timerecorded <=convert(datetime,'''+@totime+''',103) order by Timerecorded asc'exec(@query)---------------------------------------------------------------exec by this:-exec record 'USR012','10/04/2007 16:20:34.000','12/04/2007 16:20:34.000'Ranjeet Kumar Singh |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2007-04-12 : 09:04:49
|
To increase speed, I suggest a better database design. Your stored procedures should never accept database objects as parameters, and you should not be creating and dropping tables dynamically. Your tables should be constants that do not change except when you redesign your application. It is a poor design to have 1 table per UserID or something like that; all of your data should be in 1 table with the userID value as a key in that table.- Jeffhttp://weblogs.sqlteam.com/JeffS |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|
|