1TRUNCATE()                       SQL Commands                       TRUNCATE()
2
3
4

NAME

6       TRUNCATE - empty a table or set of tables
7
8

SYNOPSIS

10       TRUNCATE [ TABLE ] name [, ...] [ CASCADE | RESTRICT ]
11
12

DESCRIPTION

14       TRUNCATE quickly removes all rows from a set of tables. It has the same
15       effect as an unqualified DELETE on each table, but since  it  does  not
16       actually  scan  the  tables  it is faster. This is most useful on large
17       tables.
18

PARAMETERS

20       name   The name (optionally schema-qualified) of a table  to  be  trun‐
21              cated.
22
23       CASCADE
24              Automatically  truncate  all tables that have foreign-key refer‐
25              ences to any of the named tables, or to any tables added to  the
26              group due to CASCADE.
27
28       RESTRICT
29              Refuse  to truncate if any of the tables have foreign-key refer‐
30              ences from tables that are not to  be  truncated.  This  is  the
31              default.
32

NOTES

34       Only the owner of a table may TRUNCATE it.
35
36       TRUNCATE cannot be used on a table that has foreign-key references from
37       other tables, unless all such tables are also  truncated  in  the  same
38       command. Checking validity in such cases would require table scans, and
39       the whole point is not to do one. The CASCADE option  can  be  used  to
40       automatically  include  all dependent tables — but be very careful when
41       using this option, else you might lose data you did not intend to!
42
43       TRUNCATE will not run any user-defined ON DELETE  triggers  that  might
44       exist for the tables.
45

EXAMPLES

47       Truncate the tables bigtable and fattable:
48
49       TRUNCATE TABLE bigtable, fattable;
50
51
52       Truncate  the table othertable, and cascade to any tables that are ref‐
53       erencing othertable via foreign-key constraints:
54
55       TRUNCATE othertable CASCADE;
56
57

COMPATIBILITY

59       There is no TRUNCATE command in the SQL standard.
60
61
62
63SQL - Language Statements         2008-06-08                        TRUNCATE()
Impressum