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
 General SQL Server Forums
 New to SQL Server Programming
 truncate table

Author  Topic 

vedjha
Posting Yak Master

228 Posts

Posted - 2009-05-15 : 01:28:27
I have to truncate data from all tables of a database except few tables.
i m using sp_msforeachtable 'delete from ?'
it truncates whole database but i have to truncate only few tables.
plz help ,,,its urgent

Ved Prakash Jha

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-05-15 : 01:59:37
You can write an IF clause in the parameter string.


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-05-15 : 03:55:10
or you can change this accordingly
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=65341

Madhivanan

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

chriztoph
Posting Yak Master

184 Posts

Posted - 2009-05-31 : 23:17:36
[code]SELECT 'TRUNCATE TABLE ' + TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
[/code]

then copy the tables to the text editor you want to truncate the execute
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-06-01 : 02:25:40
quote:
Originally posted by chriztoph

SELECT 'TRUNCATE TABLE ' + TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES


then copy the tables to the text editor you want to truncate the execute


You can't truncate table which is referenced by a FOREIGN KEY constraint. See the link I posted


Madhivanan

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

- Advertisement -