views:

42

answers:

4

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?

+1  A: 

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;
Daniel Vassallo
+2  A: 

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

Daniel Egeberg
+3  A: 

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.

Dennis Haarbrink
A: 

Create stored procedure p with your query

and type

   call p
Michael Pakhantsov