Articulu Directory
MySQLCumu creà / abbandunà una tavula tempestiva?MySQLU rolu di e tavule tempuranee
Tavola temporanea MySQL
I tavule tempurane MySQL sò assai utili quandu avemu bisognu di almacenà qualchi dati tempuranee.I tavule temporali sò visibili solu in a cunnessione attuale. Quandu a cunnessione hè chjusa, Mysql sguasserà automaticamente a tavola è libera tuttu u spaziu.
E tavule tempurane sò state aghjunte in a versione MySQL 3.23. Se a vostra versione MySQL hè più bassu di a versione 3.23, ùn pudete micca aduprà e tavule temporali MySQL.Tuttavia, hè raru à aduprà una versione cusì bassa avà.basa di dati MySQLserviziu.
A tavola temporanea di MySQL hè visibile solu à a cunnessione attuale.Se utilizate un script PHP per creà una tavola temporanea MySQL, a tavola temporanea serà automaticamente distrutta ogni volta chì u script PHP hè eseguitu.
Se utilizate un altru prugramma cliente MySQL per cunnette à u servitore di basa di dati MySQL per creà una tavola temporale, a tavula temporale serà distrutta solu quandu u prugramma cliente hè chjusu.Di sicuru, pudete ancu distrughje manualmente.
Istanza
U seguitu mostra un esempiu simplice di utilizà a tavola temporanea MySQL, u seguente codice SQL pò esse appiicatu à a funzione mysql_query () di u script PHP.
MySQL的> CREATE TEMPORARY TABLE SalesSummary (- > PRODUCT_NAME VARCHAR (50 )NOT NULL - > ,TOTAL_SALES DECIMAL (12 ,2 )NOT NULL DEFAULT 0.00 - > ,avg_unit_price DECIMAL (7 ,2 )NOT NULL DEFAULT 0.00 - > ,total_units_sold INT UNSIGNED NOT NULL DEFAULT 0 ); 查询OK ,0 行受影响(0.00 秒 ) 的MySQL > INSERT INTO SalesSummary - > (PRODUCT_NAME ,TOTAL_SALES ,avg_unit_price ,total_units_sold )- > VALUES - > ('黄瓜' ,100.25 ,90 ,2 ); mysql > SELECT * FROM SalesSummary ; + -------------- + ------------- + ---------------- + --- --------------- + | product_name | total_sales | avg_unit_price | total_units_sold | + -------------- + ------------- + ---------------- + --- --------------- + | 黄瓜 | 100.25 | 90.00 | 2 | + -------------- + ------------- + ---------------- + --- --------------- + 1 行中集合(0.00 秒)
quandu aduprateSHOW TABLESQuandu u cumandamentu mostra a lista di e tavule di dati, ùn puderete micca vede a tabella SalesSummary.
Se esce da a sessione MySQL attuale, allora utilizateSELECTcumanda per leghje i dati di u tavulu pruvisoriu creatu in origine, allora truverete chì a tavula ùn esiste micca in a basa di dati, perchè a tavola temporale hè stata distrutta quandu esce.
Drop MySQL table temporary
Per automaticamente, i tavule temporali sò automaticamente distrutte quandu si disconnette da a basa di dati.Di sicuru, pudete ancu aduprà in a sessione MySQL attualeDROP TABLEcumanda per abbandunà manualmente a tavola temporale.
U seguente hè un esempiu di abbandunà manualmente una tavola temporale:
mysql> CREATE TEMPORARY TABLE SalesSummary ( -> product_name VARCHAR(50) NOT NULL -> , total_sales DECIMAL(12,2) NOT NULL DEFAULT 0.00 -> , avg_unit_price DECIMAL(7,2) NOT NULL DEFAULT 0.00 -> , total_units_sold INT UNSIGNED NOT NULL DEFAULT 0 ); Query OK, 0 rows affected (0.00 sec) mysql> INSERT INTO SalesSummary -> (product_name, total_sales, avg_unit_price, total_units_sold) -> VALUES -> ('cucumber', 100.25, 90, 2); mysql> SELECT * FROM SalesSummary; +--------------+-------------+----------------+------------------+ | product_name | total_sales | avg_unit_price | total_units_sold | +--------------+-------------+----------------+------------------+ | cucumber | 100.25 | 90.00 | 2 | +--------------+-------------+----------------+------------------+ 1 row in set (0.00 sec) mysql>DROP TABLE SalesSummary ; mysql > SELECT * FROM SalesSummary ; 错误1146 :表'chenweiliang.SalesSummary' 不存在
Hope Chen Weiliang Blog ( https://www.chenweiliang.com/ ) hà spartutu "Cumu MySQL crea / sguassate una tavola pruvisoria? U Role di MySQL Tempurary Tables" per aiutà.
Benvenuti à sparte u ligame di stu articulu:https://www.chenweiliang.com/cwl-497.html
