0

If I create a temporary SQL table with a cron job, can I use it after the cron job completes or it is destroyed right after that?

What I want to do is to create a temporary table with a cron job and then access it's contents during the next hour or so with another cron job.

Any additional info that you think might be useful will be appreciated.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
BradG
  • 673
  • 1
  • 14
  • 26
  • http://stackoverflow.com/questions/2920836/local-and-global-temporary-tables-in-sql-server – Damodaran Dec 26 '14 at 11:30
  • A much better wording would be: do MySQL temporary tables persist beyond session? I don't know the answer but, if that's relevant for you, I don't think you should be using temporary tables to begin with. Said that, didn't you just try? – Álvaro González Dec 26 '14 at 11:53
  • @Damodaran - Whatever SQL Server does with temporary tables, it's unlikely you can extrapolate it to MySQL. – Álvaro González Dec 26 '14 at 11:53

1 Answers1

2

I think the MySQL documentation is pretty clear on this subject:

> Temporary Tables
> 
> You can use the TEMPORARY keyword when creating a table. A TEMPORARY
> table is visible only to the current session, and is dropped
> automatically when the session is closed.

You would have to know that a "cron" job is going to create a new session, but that is rather obvious because such a job would typically initiate a new connect to the database.

So, a temporary table is not going to be visible after the cron job is completed. Nor is it available to other jobs or queries running at the same time in other sessions.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786