Dropping table conditionally

  • Folks,

    Is it possible to drop a table based on some criteria e.g.

    drop table where......

    Thanks

    Mick

  • Hi

    I would do it in the following manner:

    if (select count (*) from Tablename) > 8

    begin

    drop table tablename

    end

  • thanks Kevin,

    So I guess it is not possible to apply conditionals directly to a drop statement then

  • [font="Verdana"]Yup, condition can not be placed on Drop statement.[/font]

    MH-09-AM-8694

  • Thanks folks,

    I got there in the end.

    while EXISTS(SELECT * FROM sysobjects WHERE name like '%' + @table_Name + '%')

    BEGIN

    SELECT @found_name = [name] FROM sysobjects WHERE name like '%' + @table_Name + '%'

    SET @sqlCommand = 'DROP TABLE ' + @found_name

    EXEC (@sqlCommand)

    END

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply