-
July 28th, 2008, 11:11 PM
#1
How to Delete All tables' records?
Hi, I want to delete all tables' all rows by one query execution. so i need to write "Delete From tableName" again and again, as the numbers of tables. Is there any keyword or way to delete all rows of a database consisting more than 20 tables? Thanks.
-
July 28th, 2008, 11:14 PM
#2
Re: How to Delete All tables' records?
that sounds like it's pretty dangerous to be posting on the web. kind of like how do i delete all files on my system? we don't answer things like that.
You might want to 'find all the tables' in a database, maybe...
-
July 29th, 2008, 03:08 AM
#3
Re: How to Delete All tables' records?
You cant do that in just one query.
Instead of having to type the query for every table over and over again just make a small php script that does it.
-
July 29th, 2008, 05:43 AM
#4
Re: How to Delete All tables' records?
Hi all
You didn't say what db you're using, but in any case there isn't a SQL command that cleans the whole database (as Teranoz pointed out). To solve this problem I used to create a script that contains the DELETE commands for all tables; I get this script writing a query on tables of dictionary that builds the commands.
For example, with Oracle database you can write something like this:
Code:
SELECT 'DELETE FROM ' || OBJECT_NAME || ';'
FROM USER_OBJECTS
WHERE OBJECT_TYPE = 'TABLE'
Of course, you need to run the commands in the correct order...
-
July 30th, 2008, 01:40 AM
#5
Re: How to Delete All tables' records?
Thanks All. I'd like to make this delete process in MS SQL Server 2005. I tried to search the Delete syntax such as Oracle. But in MS SQL, I did not find User_Objects and only found Object_Type. If MS SQL has some way, pls tell me it, davide++.
-
July 30th, 2008, 02:41 AM
#6
Re: How to Delete All tables' records?
This query in SQL 2005 will give you the names of all the tables
PHP Code:
Select Object_name(object_id) from sys.objects where type = 'U'
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
|