SQL Server - How can we truncate all tables in Database?

sp_msforeachtable can be used to truncate tables from the database. sp_msforeachtable is undocumented means this is not documented by Microsoft it can be changed or modified at any time. It contains two parameters @command1 and @whereand using this procedure we can truncate tables.

If you want to truncate all the tables in the database then use the following query.

Exec Sp_msforeachtable @command1='Truncate Table ?'

If you want to truncate all the tables of particular schema then use the following query

Exec Sp_msforeachtable @command1='Truncate Table ?',@whereand='and Schema_Id=Schema_id(''schema_name'')'

PostgreSQL-Query: Sort result set by specific field values using ORDER BY Clause

Problem: Suppose we have a book_inventory table which has some columns such as id, isbn, title, author, publisher, publish_date, etc.. whe...