Is this syntax correct?

  • Hello,

    I am trying to delete all records in all tables in a single database. Which of these stored procedure syntax is correct for doing that?

    exec sp_msforeachtable 'truncate table tablename'

    or

    exec sp_msforeachtable 'delete table tablename'

     

    Also...I am assuming that these stored procedures would NOT alter any of those sytem(sys) tables in the database.

     

    Thanks.

    Ram


    Thanks,

    Ram Ganesan

  • Do not use the second version, that will actually delete the table.

    The first is roughly correct, but you need to used to parm coming back from "ForEachTable" instead of TableName

     

    It's a little tricky, so I don't gaurantee this is exact.

    exec sp_msforeachtable 'truncate table "?"'

    The "?" with double quotes does the parameter replacement.


    KlK

Viewing 2 posts - 1 through 1 (of 1 total)

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