Delete tables having exactly 10 rows in MySQL -
is possible delete tables 10 records in single statement using statement this?
.. drop table ... name in (select table_name information_schema.tables table_schema = 'my_db' , table_rows = 10);
first of all, don't trust table_rows
in information_schema.tables. it's estimate, it's not precise. how precise, given @ given moment, there might transactions uncommitted either insert or delete rows? number of rows in table may or may not include changes.
secondly, drop table
statement supports fixed list of tables drop. here's syntax reference http://dev.mysql.com/doc/refman/5.7/en/drop-table.html:
drop [temporary] table [if exists] tbl_name [, tbl_name] ... [restrict | cascade]
this statement not support where
clause or conditions. must name tables explicitly.
you should develop habit of reading documentation find out syntax supported. biggest complaint have questions on stack overflow: many people skip reading reference documentation. 90% or more of questions here unnecessary if did.
as @barmar comments above, can prepare dynamic sql statement list of tables want drop.
thirdly, dropping indeterminate set of tables dangerous. drop wrong tables, due bug in code finds tables match criteria. sure create disaster of data loss can't recover from. never "automate" dropping of tables.
Comments
Post a Comment