Главная страница
Содержание
 
 
Скачать архив

CREATE/DROP TABLE

 

CREATE TABLE will create a new, initially empty table in the database.

Synopsis: 
               CREATE TABLE table_name ( 
               [ { column_name data_type [DEFAULT expr] 
                               [column_constraint […] ] 
               | table_constraint  } ] );

The CREATE TABLE executed looks as follows:

CREATE TABLE tpost

(

  id integer NOT NULL DEFAULT nextval('tpost_id_seq'::regclass),

  name text NOT NULL,

  shortname character varying(50),

  CONSTRAINT tpost_pkey PRIMARY KEY (id)

);

CREATE TABLE statement specifies the name of the base table to be created, the names and types of the columns of that table, and the primary key and any foreign keys in that table.

DROP TABLE removes tables from the database. To empty a table of rows without destroying the table, use DELETE.

Synopsis:

               DROP TABLE [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ]

Next example assumes that we have table with name «tpos» and shows how to use drop clause.

DROP TABLE tpost; -- remove table tpost

“--" use for comments.

<< К содержанию >>