Stored procedure + truncate table

  • I would like to create a procedure that will truncate a table by a given name passed by parameter

    create procedure ds_truncatetable(@tablename varchar(60))

    as

    //code goes here

    go

    Thanx

  • create procedure ds_truncatetable(@tablename varchar(60))

    as

    exec ('truncate table '+@tablename)

    go

    ------------
    Prakash Sawant

    http://psawant.blogspot.com

  • Note that if the table has referential integrity constraints then you cannot just "truncate" it, even if it is technically empty.  you'll have to use delete from [tablename] in that case.

    Odd requirement to want to truncate a table based on its name - perhaps DB not designed well?

  • Thanx alot Prakash Sawant and Ian Yates

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

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