CREATE TEMPORARY TABLE : Temporary Table « Table Index « SQL / MySQL






CREATE TEMPORARY TABLE

     
mysql>
mysql> CREATE   TABLE PENALTIES
    ->         (PAYMENTNO      INTEGER      NOT NULL,
    ->          PLAYERNO       INTEGER      NOT NULL,
    ->          PAYMENT_DATE   DATE         NOT NULL,
    ->          AMOUNT         DECIMAL(7,2) NOT NULL,
    ->          PRIMARY KEY    (PAYMENTNO)          );

mysql>
mysql> INSERT INTO PENALTIES VALUES (1,  6, '1980-12-08',100);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (2, 44, '1981-05-05', 75);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (3, 27, '1983-09-10',100);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (4,104, '1984-12-08', 50);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (5, 44, '1980-12-08', 25);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (6,  8, '1980-12-08', 25);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (7, 44, '1982-12-30', 30);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (8, 27, '1984-11-12', 75);
Query OK, 1 row affected (0.00 sec)

mysql>
mysql> CREATE TEMPORARY TABLE SUMPENALTIES
    ->       (TOTAL DECIMAL(10,2))
    -> ;
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO SUMPENALTIES
    -> SELECT SUM(AMOUNT)
    -> FROM   PENALTIES;
Query OK, 1 row affected (0.00 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql>
mysql> drop table PENALTIES;
Query OK, 0 rows affected (0.00 sec)

mysql>

   
    
    
    
    
  








Related examples in the same category

1.Using Temporary Tables
2.Give ordinary users the ability to lock (LOCK) tables, create temporary tables, and execute stored procedures.
3.Copying to a Temporary Table
4.Creating Temporary Tables
5.A temporary table can be created by adding the keyword TEMPORARY to the CREATE TABLE statement:
6.Duplicate table name between normal table and temporary table
7.Memory engine for temporary table
8.Create a TEMPORARY TABLE;