- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
- Is it possible to have a function-based index in MySQL?
- Underscore as a table name in MySQL is possible?
- Pull and add to set at the same time with MongoDB? Is it Possible?
- How many public classes of the same name it can have in Java?
- Is it possible to sort varchar data in ascending order that have both string and number values with MySQL?
- Is it possible to make an insert or an update in the same MySQL query?
- Is it possible to utilize $addToSet multiple times in the same update?
- Get rows that have common value from the same table with different id in MySQL
- Is it possible to use UPDATE query with LIMIT 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 have multiple try blocks with only one catch block in java?
- Can a method have the same name as the class?
- Is it possible to use variable for collection name using PyMongo?