|
-
Aug 2nd, 2007, 03:41 AM
#1
Thread Starter
Just Married
[RESOLVED] delete all data from all table
Hi all
I have a database in SQL SERVER 2005
that contaion 35 table
I want to clear all the table data using one query plese guide me!
I do not want to delete using while loop!
Thanks
-
Aug 2nd, 2007, 04:39 AM
#2
Frenzied Member
Re: delete all data from all table
I don't use SQL Server, but don't know of anyway to delete all from 35 tables in one query. Maybe there's a way to copy just the structure of the db to another one. What's the problem with using a loop?
Tengo mas preguntas que contestas
-
Aug 2nd, 2007, 04:52 AM
#3
Re: delete all data from all table
Delete the database and then create it again. No loop required.
-
Aug 2nd, 2007, 05:32 AM
#4
Re: delete all data from all table
Or, rather than deleting the database, drop all the tables and recreate them.
My I ask what the issue with using a loop might be?
-
Aug 2nd, 2007, 06:33 AM
#5
Re: delete all data from all table
Create a Script that will drop and then recreate the tables. Don't forget about indexes and primary keys.
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Aug 2nd, 2007, 07:12 AM
#6
Re: delete all data from all table
How about just...
Code:
Truncate Table SomeTableA; Truncate Table SomeTableB; Truncate Table Sometable C;...
and so on
If that's a problem for you then create a stored procedure called TruncateAllMyTables and put the 35 truncate statements in that SPROC - and just execute it.
If you have lots of referential integrity between tables you might need to use DELETE FROM SOMETABLEA instead - but of course that is lots and lots slower and use the log file (which will expand it greatly).
-
Aug 2nd, 2007, 07:15 AM
#7
Re: delete all data from all table
Wouldn't Truncate have issues if there are FK relationships to of the table? I know that Oracle will not allow a tracate if the table is a Parent in a FK relationship.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Aug 2nd, 2007, 07:53 AM
#8
Re: delete all data from all table
That is what I meant by...
 Originally Posted by szlamany
If you have lots of referential integrity between tables you might need to use DELETE FROM SOMETABLEA instead - but of course that is lots and lots slower and use the log file (which will expand it greatly).
-
Aug 2nd, 2007, 08:26 AM
#9
Thread Starter
Just Married
Re: delete all data from all table
 Originally Posted by szlamany
How about just...
Code:
Truncate Table SomeTableA; Truncate Table SomeTableB; Truncate Table Sometable C;...
and so on
If that's a problem for you then create a stored procedure called TruncateAllMyTables and put the 35 truncate statements in that SPROC - and just execute it.
If you have lots of referential integrity between tables you might need to use DELETE FROM SOMETABLEA instead - but of course that is lots and lots slower and use the log file (which will expand it greatly).
Thanks sir for guidence
I want to ask what is best to do?
Truncate or delete statement??
-
Aug 2nd, 2007, 08:30 AM
#10
Re: delete all data from all table
If there is referential integrity between tables then you must use Delete on the Parent side of the relationship. Truncate on any other table.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Aug 2nd, 2007, 08:32 AM
#11
Re: delete all data from all table
As Gary said - TRUNCATE will fail with an error if there are foreign keys and what not.
Try TRUNCATE TABLE - if it fails - change it do DELETE FROM.
-
Aug 3rd, 2007, 01:59 AM
#12
Thread Starter
Just Married
Re: delete all data from all table
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|