470,647 Members | 1,248 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,647 developers. It's quick & easy.

Difference between REFERENCES and FOREIGN KEY

Hello
When we create a table, what is the difference between
the REFERENCE constraint on column and the FOREIGN KEY constraint on table ?

I guess that the FOREIGN KEY constraint assures us that the referenced column is
a PRIMARY KEY in an another table.
You can reference any colums with the REFERENCE constraint on column.

Am I right?

If no, what is the difference?

If yes, if I reference a foreign key in the column constraint, am I doing
something wrong?
Here's the doc about creating table:
CREATE TABLE

Creates a new table

Synopsis

CREATE [ TEMPORARY | TEMP ] TABLE table_name (
{ column_name type [ column_constraint [ ... ] ]
| table_constraint } [, ... ]
) [ INHERITS ( inherited_table [, ... ] ) ]

where column_constraint can be:
[ CONSTRAINT constraint_name ]
{ NOT NULL | NULL | UNIQUE | PRIMARY KEY | DEFAULT value | CHECK (condition)
|
REFERENCES table [ ( column ) ] [ MATCH FULL | MATCH PARTIAL ]
[ ON DELETE action ] [ ON UPDATE action ]
[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE
]
}

and table_constraint can be:
[ CONSTRAINT constraint_name ]
{ UNIQUE ( column_name [, ... ] ) |
PRIMARY KEY ( column_name [, ... ] ) |
CHECK ( condition ) |
FOREIGN KEY ( column_name [, ... ] ) REFERENCES table [ ( column [, ... ] )
]
[ MATCH FULL | MATCH PARTIAL ] [ ON DELETE action ] [ ON UPDATE action ]
[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ] }

Thank you very much

Luc

Jul 19 '05 #1
0 6099

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Randell D. | last post: by
reply views Thread by Ed Smith | last post: by
2 posts views Thread by Scott Goodwin | last post: by
2 posts views Thread by Scott Goodwin | last post: by
3 posts views Thread by Steve | last post: by
1 post views Thread by Korara | last post: by
reply views Thread by warner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.