Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't DROP TABLE because unknown table (ERROR 1051)

Tags:

mysql

I'm trying to drop a table from a schema I inherited. When I SHOW TABLES I get

+----------------------------+
| Tables_in_schema_a         |
+----------------------------+
| table_1                    |
| table_2                    |
| table_3                    |
| table_4                    |
| table_5                    |
| table_6                    |
+----------------------------+

But when I execute DROP TABLE table_1 I get

ERROR 1051 (42S02): Unknown table 'table_1'

I'm using the correct schema. What's going on?

P.S. This is MySQL server is 5.1.73.

like image 994
kas Avatar asked Apr 19 '16 15:04

kas


2 Answers

Turns out SHOW TABLES is actually a bit of a misnomer. That table, table_1, was unknown because it's actually a view. I ran SELECT table_name, table_type FROM information_schema.tables WHERE table_schema='schema_a' showed that it's a view. DROP VIEW table_1 deleted it.

like image 108
kas Avatar answered Nov 05 '22 02:11

kas


Check whether the table is a VIEW, if so use the command

drop view table_name;
like image 6
Dani Dissosa Avatar answered Nov 05 '22 02:11

Dani Dissosa