1

As per stated in the title. Does MySQL support defining locally a table? (as a 'local variable' perhaps?)

I understand (according to 'Source') that MySQL has 'two types of variables': (1) local and (2) user variables, nevertheless neither can be a whole table.


Source:


EDIT: I think that using the 'temporary' flag in 'create' is the answer

CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name

from the docs: https://dev.mysql.com/doc/refman/8.0/en/create-table.html

  • Yes what you're looking for is called a TEMPORARY TABLE. – J.D. Jan 9 at 14:51
  • what you want ist the temporyry table as you described, they exits only in that seasion – nbk Jan 9 at 14:51
2

You are right it is a like a local table to the connection.

According to the link you have under the subheading Temporary Tables, it says:

A TEMPORARY table is visible only within the current session, and is dropped automatically when the session is closed

Simply put, once the DB Connection terminates (normally or abnormally), the table disappears.

Also, please be aware that only the DB Connection that created the temporary table can access it. If 10 different DB Connections perform CREATE TEMPORARY TABLE, each DB Connection would have its own table. No other DB Connection can access it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.