in reply to T-SQL problem - Perl solution?

Another alternative:
if exists (select * from sysobjects where type = 'U' and name = 'table +_name') begin drop table table_name end
Note that you also need to take the object owne into account - the code above assumes the table is owned by 'dbo'.

Michael

Replies are listed 'Best First'.
Re^2: T-SQL problem - Perl solution?
by EdwardG (Vicar) on Oct 25, 2004 at 11:38 UTC

    Two minor nits;

    • This works for MSSQL 2000, but may break with MSSQL 2005
    • The type column exists for backward compatibility only; xtype is the right column (if you must). They are different.

     

      Thanks.

      I'm not really an MS-SQL user - I just apply the Sybase syntax, which usually works (though it looks like MS is moving in a different direction for system tables...)

      Michael

      To be fair that is almost exactly what SQL Server 2000 emits in a new CREATE TABLE template if you have specified that you should create the appropriate DROP TABLE ...

      /J\