Using a TRUNCATE Statement to Delete Data : TRUNCATE « Table Index « SQL / MySQL

Home
SQL / MySQL
1.Aggregate Functions
2.Backup Load
3.Command MySQL
4.Cursor
5.Data Type
6.Database
7.Date Time
8.Engine
9.Event
10.Flow Control
11.FullText Search
12.Function
13.Geometric
14.I18N
15.Insert Delete Update
16.Join
17.Key
18.Math
19.Procedure Function
20.Regular Expression
21.Select Clause
22.String
23.Table Index
24.Transaction
25.Trigger
26.User Permission
27.View
28.Where Clause
29.XML
SQL / MySQL » Table Index » TRUNCATE 
Using a TRUNCATE Statement to Delete Data
       
mysql>
mysql> CREATE TABLE Books
    -> (
    ->     BookID SMALLINT NOT NULL PRIMARY KEY,
    ->     BookName VARCHAR(40NOT NULL,
    ->     InStock SMALLINT NOT NULL
    -> )
    -> ENGINE=INNODB;
Query OK, rows affected (0.01 sec)

mysql>
mysql>
mysql> INSERT INTO Books
    -> VALUES (101'C: Writing on Writing', 12),
    -> (102'Oracle', 17),
    -> (103'Opera', 23),
    -> (104'Notebook', 32),
    -> (105'Pascal', 6),
    -> (106'One Hundred Years of Solitude', 28);
Query OK, rows affected (0.00 sec)
Records: 6  Duplicates: 0  Warnings: 0

mysql>
mysql> CREATE TABLE Orders
    -> (
    ->     OrderID SMALLINT NOT NULL PRIMARY KEY,
    ->     BookID SMALLINT NOT NULL,
    ->     Quantity TINYINT (40NOT NULL DEFAULT 1,
    ->     DateOrdered TIMESTAMP,
    ->     FOREIGN KEY (BookIDREFERENCES Books (BookID)
    -> )
    -> ENGINE=INNODB;
Query OK, rows affected (0.01 sec)

mysql>
mysql> INSERT INTO Orders VALUES (10011031'2004-10-12 12:30:00'),
    -> (10021011'2004-10-12 12:31:00'),
    -> (10031032'2004-10-12 12:34:00'),
    -> (10041043'2004-10-12 12:36:00'),
    -> (10051021'2004-10-12 12:41:00'),
    -> (10061032'2004-10-12 12:59:00'),
    -> (10071011'2004-10-12 13:01:00'),
    -> (10081031'2004-10-12 13:02:00'),
    -> (10091024'2004-10-12 13:22:00'),
    -> (10101012'2004-10-12 13:30:00'),
    -> (10111031'2004-10-12 13:32:00');
Query OK, 11 rows affected (0.00 sec)
Records: 11  Duplicates: 0  Warnings: 0

mysql>
mysql>
mysql> TRUNCATE TABLE Orders;
Query OK, rows affected (0.00 sec)

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

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

   
    
    
    
    
    
    
  
Related examples in the same category
1.TRUNCATE TABLE
2.More about Removing Records (DELETE and TRUNCATE)
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.