tags:

views:

1344

answers:

4

I need to clear all my inventory tables.

I've tryed

SELECT 'TRUNCATE TABLE ' + TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE 'inventory%'

but I get this error:

Truncated incorrect DOUBLE value: 'TRUNCATE TABLE ' Error Code 1292

if this is the correct way, then what am I doing wrong?

A: 
SELECT CONCAT('TRUNCATE TABLE ',TABLE_NAME)
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE 'inventory%'

You should then take every row of the result set and call it as the SQL statement. You can do it by coping and pasting the separated results to the command window.

But much better solution is to write some program which will make the query above and loop through the results and make every query.

Use PHP for that or any other scripting language. Many examples even here on SO.

Lukasz Lysik
+3  A: 

Use concat:

SELECT concat('TRUNCATE TABLE ', TABLE_NAME, ';')
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE 'inventory%'

This will of course only generate sql which you need to copy and run yourself.

ʞɔıu
ok so I copied the result, pasted it in the query browser, hit CtrlEnter and boooom!!!! nothing happended, tables still with data =(
Luiscencio
Any error message?
Lukasz Lysik
it seems that I have to execute each line in the query browser, well at least I don't have to write all the lines, just pres CtrlEnter on each one o.O
Luiscencio
must a function of your mysql client. ';' should work as a statement separator in most clients
ʞɔıu
+1  A: 

If you are using linux, you might want to try something like this.

mysql -u [user] -p[password] -e 'use [database]; show tables' | perl -lane 'print "truncate table $F[0]" if /^inventory/i' > [database].sql

bichonfrise74
A: 

Hi all,

Can any body tell me and explain it out how could we trigger two or more Query in a Single SSIS Package, means I want to execute truncate statement for a table and update statement again for the same table (First Truncate and then Update the same table) in single SSIS package.

Thanks & Regards, Rajeev.

rajeev
make a new question....
Luiscencio