How to create a synonym in mysql

半城伤御伤魂 提交于 2019-11-28 04:13:18

问题


I have a view in database B which I use in database A.

I would like to create a synonym to this view. Because right now each time I have to write the query like this

Select * from DBNAME.VIEWNAME

rather I just want to be able to write

SELECT * FROM MYSYNONYMNAME

Is that possible to do in mysql? I didn't see much in the manual..


回答1:


It's not possible to create synonyms in mysql like it's possible in Oracle




回答2:


Apparently a VIEW may work as a SYNONYM:

DROP VIEW IF EXISTS `MYSYNONYMNAME` $$
CREATE ALGORITHM=MERGE DEFINER=`root`@`localhost`
SQL SECURITY DEFINER VIEW `MYSYNONYMNAME` AS
SELECT * FROM DBNAME.VIEWNAME $$

Not sure of performance or how far you can get away stacking views within views etc. Also might need to recreate when base table columns change.

See: http://blog.mclaughlinsoftware.com/2013/11/24/mysql-synonym/



来源:https://stackoverflow.com/questions/15777420/how-to-create-a-synonym-in-mysql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!