Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Query to delete all records in all table

Author  Topic 

amirmuthu
Starting Member

12 Posts

Posted - 2008-02-18 : 06:35:20
hello Experts,
Please can you any one say the query to delete all tables records from database. because i don't want write delete query for each table

Thanks & Regards,
MuthuKrishnan Gurusamy,
Confluence Systems,
Chennai.

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-02-18 : 06:39:17
Just a perfect utility function for you: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=97454

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

amirmuthu
Starting Member

12 Posts

Posted - 2008-02-18 : 06:42:07
if i dont have a primary key then how to delete.
Please advice

Thanks & Regards,
MuthuKrishnan Gurusamy,
Confluence Systems,
Chennai.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-02-18 : 06:44:23
exec sp_msforeachtable 'truncate table ?'



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

amirmuthu
Starting Member

12 Posts

Posted - 2008-02-18 : 06:46:03
what is it?
exec sp_msforeachtable 'truncate table ?'
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-02-18 : 06:48:36
It truncates all records from all tables in your current database.

try

exec sp_msforeachtable 'print ''?'''


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

amirmuthu
Starting Member

12 Posts

Posted - 2008-02-18 : 07:00:29
Thanks its working fine
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-18 : 09:16:41
Also refer http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=65341

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -