sp_MSforeachtable Usage in xp_cmdshell, Know this!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sudhaMurugesan
    New Member
    • May 2007
    • 94

    sp_MSforeachtable Usage in xp_cmdshell, Know this!

    Hi all,
    To delete all tables from a database, I used this query

    EXEC sp_MSforeachtab le @command1 = "DROP TABLE ?"
    It worked fine.
    But this is not a rollback one, I have to manually clear the drop table command from the command prompt using this query. But its not working.Can anyone help me?

    EXEC xp_cmdshell 'SQLCMD -U sa -P Admin@fih -Q 'EXEC sp_MSforeachtab le @command1 = "DROP TABLE ?"', no_output'

    I'm getting following error message

    Msg 102, Level 15, State 1, Line 2
    Incorrect syntax near ', no_output'.
  • CyberSoftHari
    Recognized Expert Contributor
    • Sep 2007
    • 488

    #2
    [CODE=sql]EXEC xp_cmdshell 'SQLCMD -U sa -P Admin@fih -Q 'EXEC sp_MSforeachtab le @command1 = "DROP TABLE ?"', no_output'[/CODE]

    Check the quotes here.

    Comment

    • sudhaMurugesan
      New Member
      • May 2007
      • 94

      #3
      Originally posted by CyberSoftHari
      [CODE=sql]EXEC xp_cmdshell 'SQLCMD -U sa -P Admin@fih -Q 'EXEC sp_MSforeachtab le @command1 = "DROP TABLE ?"', no_output'[/CODE]

      Check the quotes here.
      No I tried by closing the quotes its not working. Is the above query is correct?
      I've got it from this link:

      Comment

      • CyberSoftHari
        Recognized Expert Contributor
        • Sep 2007
        • 488

        #4
        I am not sure. Give related topic to your Query then experts will view your thread.

        Topic : How to delete all tables in a database using store procedure?

        Comment

        • sudhaMurugesan
          New Member
          • May 2007
          • 94

          #5
          Originally posted by CyberSoftHari
          I am not sure. Give related topic to your Query then experts will view your thread.
          OK I try.Thanks for ur replies

          Comment

          • CyberSoftHari
            Recognized Expert Contributor
            • Sep 2007
            • 488

            #6
            welcome .

            Comment

            Working...