Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
1.43/5 (3 votes)
See more:
How to delete all records from all tables in SQL or Access database by utility
Posted
Updated 22-May-14 2:24am
v3
Comments
[no name] 22-May-14 8:18am    
You could try screaming at it.

run this script in sql server

SQL
declare @tblname int 
declare tbl_cursor cursor for
select name from sys.tables 
open tbl_cursor
fetch next from tbl_cursor into @tblname
while @@FETCH_STATUS = 0
begin
	EXECUTE ('truncate table '+ @tblname) 
	fetch next from tbl_cursor into @tblname
end 
close tbl_cursor
deallocate tbl_cursor 




delete-all-rows-from-all-tables/[^]
 
Share this answer
 
v3
Query for Delete All records from All Tables

C#
Exec sp_MSforeachtable 'Delete from ?'
 
Share this answer
 
Comments
CHill60 22-May-14 8:28am    
sp_MSforeachtable is an undocumented SQL Server procedure. Using undocumented features of any language or tool can set you up for problems if new versions of the product no longer provide it.
King Fisher 22-May-14 8:51am    
A few Months Ago,I got this Solution When I look For the Query to Delete all Table Records.It Was Worked. :)
CHill60 22-May-14 8:53am    
I know it works... just be wary if you upgrade - don't assume it will work in the next release of SQL Server for example. In this case it will probably stay around, but companies have been known to drop undocumented features without any notice.
King Fisher 22-May-14 8:54am    
May I know the reason for the Downvote

http://www.codeproject.com/Answers/760953/how-to-remove-decimals-without-rounding-it#answer4

[no name] 22-May-14 8:58am    
Probably for the exact same reason that everyone else that "answers" 3 year old questions that already have answers get down votes.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900