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
 SQL Server Administration (2005)
 Need a Advice

Author  Topic 

Nuwan
Starting Member

1 Post

Posted - 2008-10-16 : 16:02:05
How can i clear all the created tables in SQL Server 2005 without dropdiing them ?

Is there any way to clear all those table objects using the software?

Thank you

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-10-16 : 16:16:38
exec sp_MSforeachtable 'delete from ?'

note that sp_MSforeachtable is officially unsupported and can be removed in any future sql server version or service pack


_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.1 out!
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-10-16 : 16:30:01
Depending on relationships you can use Madhi's script to reset identity as well if you have:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=65341
Go to Top of Page

SimpleSQL
Yak Posting Veteran

85 Posts

Posted - 2008-10-16 : 22:07:19
Instead of deleting from table, you can do truncate table

exec sp_MSforeachtable 'truncate table ?'

This will be much faster (of course, this is no logged operation, but given you are removing data from all tbales, I suppose this should be ok)
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-10-16 : 22:28:45
quote:
Originally posted by SimpleSQL

Instead of deleting from table, you can do truncate table

exec sp_MSforeachtable 'truncate table ?'

This will be much faster (of course, this is no logged operation, but given you are removing data from all tbales, I suppose this should be ok)




Bear in mind that this won't work if tables have foreign keys
Go to Top of Page
   

- Advertisement -