Как уже говорилось, вы не можете делать это с представлениями, но вы можете с временными таблицами.
Если вы создаете временную таблицу с тем же именем, что и у реальной таблицы,временная таблица будет shadow (скрывать) фактическую таблицу.Это означает, что вы не можете получить доступ к фактической таблице , пока не удалите временную таблицу:
mysql> create table t select 1; # actual table t
Query OK, 1 row affected (0.58 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> create temporary table t select*from t; # temp table t
Query OK, 1 row affected (0.53 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> insert t select 2; # t refers to the temp table
Query OK, 1 row affected (0.06 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> select*from t; # temp table
+---+
| 1 |
+---+
| 1 |
| 2 |
+---+
2 rows in set (0.00 sec)
mysql> drop table t; # temp table
Query OK, 0 rows affected (0.06 sec)
mysql> show tables like "t"; # verify that actual table still exists. show tables will not show temporary tables
+--------------------+
| Tables_in_test (t) |
+--------------------+
| t |
+--------------------+
1 row in set (0.00 sec)
mysql>
mysql> select*from t; # now t refers to the actual table
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)
mysql> drop table t; # actual table
Query OK, 0 rows affected (0.14 sec)
mysql>
Однако временные таблицы исчезли (даже если вы не drop
их)) как только ваш сеанс отключен.Вам нужно будет заново создавать их при каждом подключении.