MySQL 如何在mysql中创建同义词
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15777420/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create a synonym in mysql
提问by Anthony
I have a view in database B
which I use in database A
.
我在数据库中有一个视图B
,我在数据库中使用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..
这可以在mysql中做到吗?说明书上没看到太多。。
回答by zerkms
It's not possible to create synonyms in mysql like it's possible in Oracle
无法像在 Oracle 中那样在 mysql 中创建同义词
回答by Anthony
Apparently a VIEW
may work as a SYNONYM
:
显然 aVIEW
可以用作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/
见:http: //blog.mclaughlinsoftware.com/2013/11/24/mysql-synonym/