Fix Drop table view #1051 unknown table error in MySQL


To correctly drop a view, use the below syntax −

drop view yourViewName;

Let us first create a table −

mysql> create table DemoTable
-> (
-> Id int
-> );
Query OK, 0 rows affected (1.01 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values(1001);
Query OK, 1 row affected (0.22 sec)

mysql> insert into DemoTable values(1002);
Query OK, 1 row affected (0.34 sec)

mysql> insert into DemoTable values(1003);
Query OK, 1 row affected (0.26 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

Output

This will produce the following output −

+------+
| Id   |
+------+
| 1001 |
| 1002 |
| 1003 |
+------+
3 rows in set (0.00 sec)

Let us first create a view −

mysql> create view view_DemoTable as select Id from DemoTable;
Query OK, 0 rows affected (0.23 sec)

We will now display the records of the view −

mysql> select *from view_DemoTable;

Output

This will produce the following output −

+------+
| Id   |
+------+
| 1001 |
| 1002 |
| 1003 |
+------+
3 rows in set (0.05 sec)

Following is the query to drop view −

mysql> drop view view_DemoTable;
Query OK, 0 rows affected (0.18 sec)

Now view is dropped successfully.

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 30-Jun-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements