View and table in same name is it possible

Viewed 16984

Is it possible to create a mysql view and table in same name

for example i have a table hs_hr_employee i want create a view as a same name

create VIEW hs_hr_employee AS SELECT * from hs_hr_employee;

I m getting following error

#1050 - Table 'hs_hr_employee' already exists

Any help Thankful

Regards

4 Answers

Yes, if you create it under a different schema.

for example

dbo.Customers

user.customers (this could be a view)

You can call it by including the schema or if you call it from a user that is assigned the schema.

This is for MS SQL server.

Not only in mysql server but in any sqldialect, tables and views in the same schema can't be with the same name as it will lead to ambiguity when you fire a select query like from where to select the columns either from table or view.

Related