Truncate all tables in SQL Database from single command

Today i need to blank all the tables in the SQL database. Till now I was using the truncate table command with the for loop in the code because i need to blank few tables. But now i need to blank whole database so i decided to use the sp_MSForEachTable system stored procedure like as:

EXEC sp_MSForEachTable 'TRUNCATE TABLE ?'

The command will truncate all the tables in the database but you cannot truncate tables which have foreign keys, so this will only work if there are no foreign key constraints between tables.

For it you can disable all constraints than delete data from the table and enable constraints again like as:

-- disable all constraints
EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"
 
-- delete data in all tables
EXEC sp_MSForEachTable "DELETE FROM ?"
 
-- enable all constraints
EXEC sp_msforeachtable "ALTER TABLE ? WITH CHECK CHECK 
 CONSTRAINT all"

Please carefully!
You can face other difficulties to run the above statements because this is totally depends on your database’s structure.