Accessing a temporary table multiple times in MySql

前端 未结 4 1910
伪装坚强ぢ
伪装坚强ぢ 2021-01-12 23:29

I have tried to use a temporary table as an intermediate result holder for a SELECT statement. The problem is though that I can\'t access the temp table multiple times in ot

4条回答
  •  情深已故
    2021-01-13 00:13

    One way around this is to simply create a "real" table, rather than a temporary table.

    The advantages that temporary tables offer:

    1. Namespacing. You can create multiple temporary tables with the same name in separate sessions.
    2. Automatic cleanup. You don't need explicitly drop the table when you're done with it. It goes away when you end your session

    If #1 is crucial for you, then you probably need to stick with temporary tables. Otherwise, if only one instance of this program runs at a time, or if you create the table name dynamically to make it unique, I recommend that you choose an appropriately unique name for this table and create it as a "real" table, then drop it when you're done.

提交回复
热议问题