THIS NEEDS TO BE AMMENDED FOR POSTGRESQL
The basics:
Even in a simple example such as the one above, there are few items worth noting. First, I like to define the key column(s) at the very top. Second, the
CREATE TABLE your_table_name (
the_key_column key_data_type PRIMARY KEY,
a_regular_column a_data_type,
an_important_column a_data_type NOT NULL,
... up to 996 intervening columns in Oracle8 ...
the_last_column a_data_type
);
primary key constraint has some powerful
effects. It forces the_key_column to be non-null. It
causes the creation of an index on the_key_column, which
will slow down updates to your_table_name but improve the
speed of access when someone queries for a row with a particular value
of the_key_column. Oracle checks this index when inserting
any new row and aborts the transaction if there is already a row with
the same value for the_key_column. Third, note that there
is no comma following the definition of the last row. If you are
careless and leave the comma in, Oracle will give you a very confusing
error message.
If you didn't get it right the first time, you'll probably want to
or
alter table your_table_name add (new_column_name a_data_type any_constraints);
In Oracle 8i you can drop a column:
alter table your_table_name modify (existing_column_name new_data_type new_constraints);
(see http://www.oradoc.com/keyword/drop_column).
alter table your_table_name drop column existing_column_name;
If you're still in the prototype stage, you'll probably find it easier to simply
and recreate it. At any time, you can see what you've got defined in the database by querying Oracle's Data Dictionary:
drop table your_table_name;
after which you will typically type
SQL> select table_name from user_tables order by table_name;
TABLE_NAME
------------------------------
ADVS
ADV_CATEGORIES
ADV_GROUPS
ADV_GROUP_MAP
ADV_LOG
ADV_USER_MAP
AD_AUTHORIZED_MAINTAINERS
AD_CATEGORIES
AD_DOMAINS
AD_INTEGRITY_CHECKS
BBOARD
...
STATIC_CATEGORIES
STATIC_PAGES
STATIC_PAGE_AUTHORS
USERS
...
describe
table_name_of_interest in SQL*Plus:
Note that Oracle displays its internal data types rather than the ones you've given, e.g.,
SQL> describe users;
Name Null? Type
------------------------------- -------- ----
USER_ID NOT NULL NUMBER(38)
FIRST_NAMES NOT NULL VARCHAR2(100)
LAST_NAME NOT NULL VARCHAR2(100)
PRIV_NAME NUMBER(38)
EMAIL NOT NULL VARCHAR2(100)
PRIV_EMAIL NUMBER(38)
EMAIL_BOUNCING_P CHAR(1)
PASSWORD NOT NULL VARCHAR2(30)
URL VARCHAR2(200)
ON_VACATION_UNTIL DATE
LAST_VISIT DATE
SECOND_TO_LAST_VISIT DATE
REGISTRATION_DATE DATE
REGISTRATION_IP VARCHAR2(50)
ADMINISTRATOR_P CHAR(1)
DELETED_P CHAR(1)
BANNED_P CHAR(1)
BANNING_USER NUMBER(38)
BANNING_NOTE VARCHAR2(4000)
number(38) rather than
integer and varchar2 instead of the specified
varchar.