Deleting all tables from database in one query

  • If i want to delete all the tables from the database which are user table then how to do in one query. i do not want to use cursor or stored proceduere is there any way to solve this in one query.

    vijay verma


    vijay verma

  • sp_msforeachtable 'drop table ?'

    will do it , but am curious why are you doing this.

  • quote:


    i do not want to use cursor or stored proceduere is there any way to solve this in one query.


    Sorry that would be a no. Nazim has the best suggestion but you will need to use a cursor or SP unless you want to build the queries like so.

    SELECT '

    DROP TABLE [' + [name] + ']

    GO' FROM sysobjects WHERE xtype = 'U'

    It will then generate the indvidual tiems which you can copy and run from another window.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

  • Thanks for ur suggestion but my task was different.

    The answer what u had given is only list all the table with drop syntex.

    what i want in one query i should be able to delete not that i shuld select the syntex and then run again.

    vijay verma


    vijay verma

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

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