taji01 taji01 - 1 year ago 113
SQL Question

Truncate multiple tables in SQL Server using stored procedure

I'm using SQL Server. I want to create a stored procedure that truncates 3 of my tables (


I want to clear out all of my tables this way. What am I missing?

CREATE PROCEDURE truncate_tables()
truncate table dbo.table1
truncate table dbo.table2
truncate table dbo.table3

Answer Source

Remove () next to the stored procedure name. () required if you are passing any parameter to the SP.

Add ; in end of each TRUNCATE TABLE statement as query terminator.

CREATE PROCEDURE truncate_tables
    TRUNCATE TABLE dbo.table1;
    TRUNCATE TABLE dbo.table2;
    TRUNCATE TABLE dbo.table3;