
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Is it possible to have View and table with the same name in MySQL?
No, you cannot give the same name for view and table in MySQL.
Let us first create a demo table −
mysql> create table view_Table_Demo -> ( -> Id int, -> Name varchar(20) -> ); Query OK, 0 rows affected (0.80 sec)
Now you can insert some records in the table using insert command. The query is as follows −
mysql> insert into view_Table_Demo values(100,'Larry'); Query OK, 1 row affected (0.17 sec) mysql> insert into view_Table_Demo values(101,'Mike'); Query OK, 1 row affected (0.20 sec) mysql> insert into view_Table_Demo values(102,'Sam'); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement. The query is as follows −
mysql> select *from view_Table_Demo;
Here is the output −
+------+-------+ | Id | Name | +------+-------+ | 100 | Larry | | 101 | Mike | | 102 | Sam | +------+-------+ 3 rows in set (0.00 sec)
Here you will get an error if you try to give same name for view and table. The query and the error is as follows −
mysql> create VIEW view_Table_Demo AS SELECT * from view_Table_Demo; ERROR 1050 (42S01): Table 'view_Table_Demo' already exists NOTE: To avoid the above error, try to give different name.
- Related Articles
- Underscore as a table name in MySQL is possible?
- Is it possible to have a function-based index in MySQL?
- Is it possible to sort varchar data in ascending order that have both string and number values with MySQL?
- Pull and add to set at the same time with MongoDB? Is it Possible?
- Is it possible to make an insert or an update in the same MySQL query?
- Is it possible to use UPDATE query with LIMIT in MySQL?
- Get rows that have common value from the same table with different id in MySQL
- Add a new column to table and fill it with the data of two other columns of the same table in MySQL?
- Is it possible to utilize $addToSet multiple times in the same update?
- Is it possible to have multiple try blocks with only one catch block in java?
- How to create a table from view in MySQL?
- How many public classes of the same name it can have in Java?
- How to display MySQL Table Name with columns?
- Create a table if it does not already exist and insert a record in the same query with MySQL
- Searching 2 fields at the same time to fetch a specific First Name and Last Name from a table in MySQL

Advertisements