Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > a866202fe868538f89a755dbcabc378b > files > 736

postgresql8.2-docs-8.2.14-1mdv2010.0.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>TRUNCATE</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REV="MADE"
HREF="mailto:pgsql-docs@postgresql.org"><LINK
REL="HOME"
TITLE="PostgreSQL 8.2.14 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="SQL Commands"
HREF="sql-commands.html"><LINK
REL="PREVIOUS"
TITLE="START TRANSACTION"
HREF="sql-start-transaction.html"><LINK
REL="NEXT"
TITLE="UNLISTEN"
HREF="sql-unlisten.html"><LINK
REL="STYLESHEET"
TYPE="text/css"
HREF="stylesheet.css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=ISO-8859-1"><META
NAME="creation"
CONTENT="2009-09-04T05:25:47"></HEAD
><BODY
CLASS="REFENTRY"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="5"
ALIGN="center"
VALIGN="bottom"
>PostgreSQL 8.2.14 Documentation</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="sql-start-transaction.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="sql-start-transaction.html"
>Fast Backward</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="top"
><A
HREF="sql-unlisten.html"
>Fast Forward</A
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="top"
><A
HREF="sql-unlisten.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="SQL-TRUNCATE"
></A
>TRUNCATE</H1
><DIV
CLASS="REFNAMEDIV"
><A
NAME="AEN54914"
></A
><H2
>Name</H2
>TRUNCATE&nbsp;--&nbsp;empty a table or set of tables</DIV
><A
NAME="AEN54917"
></A
><DIV
CLASS="REFSYNOPSISDIV"
><A
NAME="AEN54919"
></A
><H2
>Synopsis</H2
><PRE
CLASS="SYNOPSIS"
>TRUNCATE [ TABLE ] <TT
CLASS="REPLACEABLE"
><I
>name</I
></TT
> [, ...] [ CASCADE | RESTRICT ]</PRE
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN54922"
></A
><H2
>Description</H2
><P
>   <TT
CLASS="COMMAND"
>TRUNCATE</TT
> quickly removes all rows from a set of
   tables. It has the same effect as an unqualified
   <TT
CLASS="COMMAND"
>DELETE</TT
> on each table, but since it does not actually
   scan the tables it is faster. This is most useful on large tables.
  </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN54927"
></A
><H2
>Parameters</H2
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="REPLACEABLE"
><I
>name</I
></TT
></DT
><DD
><P
>      The name (optionally schema-qualified) of a table to be truncated.
     </P
></DD
><DT
><TT
CLASS="LITERAL"
>CASCADE</TT
></DT
><DD
><P
>      Automatically truncate all tables that have foreign-key references
      to any of the named tables, or to any tables added to the group
      due to <TT
CLASS="LITERAL"
>CASCADE</TT
>.
     </P
></DD
><DT
><TT
CLASS="LITERAL"
>RESTRICT</TT
></DT
><DD
><P
>      Refuse to truncate if any of the tables have foreign-key references
      from tables that are not to be truncated.  This is the default.
     </P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN54946"
></A
><H2
>Notes</H2
><P
>   Only the owner of a table may <TT
CLASS="COMMAND"
>TRUNCATE</TT
> it.
  </P
><P
>   <TT
CLASS="COMMAND"
>TRUNCATE</TT
> cannot be used on a table that has foreign-key
   references from other tables, unless all such tables are also truncated
   in the same command.  Checking validity in such cases would require table
   scans, and the whole point is not to do one.  The <TT
CLASS="LITERAL"
>CASCADE</TT
>
   option can be used to automatically include all dependent tables &mdash;
   but be very careful when using this option, else you might lose data you
   did not intend to!
  </P
><P
>   <TT
CLASS="COMMAND"
>TRUNCATE</TT
> will not run any user-defined <TT
CLASS="LITERAL"
>ON
   DELETE</TT
> triggers that might exist for the tables.
  </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN54956"
></A
><H2
>Examples</H2
><P
>   Truncate the tables <TT
CLASS="LITERAL"
>bigtable</TT
> and <TT
CLASS="LITERAL"
>fattable</TT
>:

</P><PRE
CLASS="PROGRAMLISTING"
>TRUNCATE TABLE bigtable, fattable;</PRE
><P>
  </P
><P
>   Truncate the table <TT
CLASS="LITERAL"
>othertable</TT
>, and cascade to any tables
   that are referencing <TT
CLASS="LITERAL"
>othertable</TT
> via foreign-key
   constraints:

</P><PRE
CLASS="PROGRAMLISTING"
>TRUNCATE othertable CASCADE;</PRE
><P>
  </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN54966"
></A
><H2
>Compatibility</H2
><P
>   There is no <TT
CLASS="COMMAND"
>TRUNCATE</TT
> command in the SQL standard.
  </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="sql-start-transaction.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="sql-unlisten.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>START TRANSACTION</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="sql-commands.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>UNLISTEN</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>