开发者

How to create an MySQL query alias?

For example I use this

select * from tab1;

every 5 minutes.

Is there a way to set up an alias p so that I can just do

p

instead开发者_开发问答 and that query is executed?


This calls for a view, but in your case it isn't much shorter: create view p as selecT * From tab1;
You'd use it as: select * from p

It does get more interesting with more complex queries though.


You can create a stored procedure and then call it like CALL p.

http://dev.mysql.com/doc/refman/5.1/en/stored-routines.html


You may want to use a stored procedure. You could call it by using:

CALL p;

This is how to create a stored procedure for the example in your question:

CREATE PROCEDURE p() SELECT * FROM tab1;


Create stored procedure p with your query

and type

   call p
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜