Hoe makket / drop MySQL in tydlike tabel? De rol fan MySQL tydlike tabellen

MySQLHoe meitsje / drop in temp tafel?MySQLDe rol fan tydlike tabellen

MySQL tydlike tabel

MySQL tydlike tabel is heul nuttich as wy wat tydlike gegevens moatte bewarje.Tydlike tabellen binne allinnich sichtber yn de hjoeddeiske ferbining. As de ferbining is sletten, Mysql sil automatysk wiskje de tabel en frij alle romte.

Tydlike tabellen waarden tafoege yn MySQL ferzje 3.23. As jo ​​MySQL ferzje is leger as ferzje 3.23, kinne jo net brûke MySQL tydlike tabellen.It is lykwols seldsum om no sa'n lege ferzje te brûken.MySQL databankbetsjinning.

De tydlike tabel fan MySQL is allinnich sichtber foar de hjoeddeistige ferbining. As jo ​​in PHP-skript brûke om in tydlike MySQL-tabel te meitsjen, sil de tydlike tabel automatysk ferneatige wurde as it PHP-skript wurdt útfierd.

As jo ​​in oar MySQL-kliïntprogramma brûke om te ferbinen mei de MySQL-databaseserver om in tydlike tabel te meitsjen, sil de tydlike tabel allinich ferneatige wurde as it kliïntprogramma ôfsletten is, fansels kinne jo it ek manuell ferneatigje.

Instance

It folgjende toant in ienfâldich foarbyld fan it brûken fan MySQL tydlike tabel, de folgjende SQL-koade kin tapast wurde op de funksje mysql_query () fan it PHP-skript.

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 



                                   

  

as jo brûkeSHOW TABLESAs it kommando de list mei gegevenstabellen toant, kinne jo de tabel SalesSummary net sjen.

As jo ​​de aktuele MySQL-sesje ferlitte, brûk danÚTKIEZEkommando om de oarspronklik oanmakke tydlike tabelgegevens te lêzen, dan sille jo fine dat de tabel net bestiet yn 'e databank, om't de tydlike tabel is ferneatige as jo útgean.


Drop MySQL tydlike tabel

Standert wurde tydlike tabellen automatysk ferneatige as jo de ferbining meitsje mei de databank.Fansels kinne jo ek brûke yn 'e hjoeddeistige MySQL-sesjeDROP TABELkommando om de tydlike tabel mei de hân te fallen.

It folgjende is in foarbyld fan it manuell falle fan in tydlike tabel:

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' 存在  

发表 评论

Jo e-mailadres sil net publisearre wurde. Ferplichte fjilden wurde brûkt * Etiket

Scroll nei boppen