Alexander Farber (EED) writes:
 > So what is the best way to handle it? I could add
 > 
 >   drop table #temp1
 >   drop table #temp2
 > 
 > to the SQL statements of my script, but what happens if
 > the user presses STOP or the script times out? Should I
 > move this SQL-code to $r->register_cleanup()? Isn't it
 > too much for this handler and will it always be executed? 

You can definitely put this code in a cleanup handler.

 > Or is it possible to use transactions/$dbh->commit somehow?

Don't use transactions around create table statements - this causes
the system tables in tempdb to be locked for the duration of the
transaction, effectively making your script single threaded.

 > Also offtopic question: is it possible in Transact-SQL to
 > check if a table #temp1 exists already?

It's a little tricky with temp tables as the name used in the
sysobjects table is extended with the spid of the connection, and some
other stuff.

You could do something like this:
if exists (select * from tempdb..sysobjects where name like '#temp1%')
  begin 
    drop table #temp1
  end

This will return error #3701 if the table in fact does not exist for
this connection (you could also just go ahead and drop the tables at
the begining of the script and be prepared to ignore error 3701...)

Michael
-- 
Michael Peppler - Data Migrations Inc. - [EMAIL PROTECTED]
http://www.mbay.net/~mpeppler - [EMAIL PROTECTED]
International Sybase User Group - http://www.isug.com
Sybase on Linux mailing list: [EMAIL PROTECTED]

Reply via email to