CREATE TABLE problems: Foreign key references.

From SQLZOO
Revision as of 12:57, 21 August 2014 by Andr3w (Talk | contribs)

Jump to: navigation, search

CREATE TABLE problems: Foreign key references.

schema:scott

A foreign key should refer to a candidate key in some table. This is usually the primary key but may be a field (or list of fields) specified as UNIQUE.

You must have REFERENCE permission on the table being referenced.

DROP TABLE t_stupid
 
CREATE TABLE customer(id INTEGER PRIMARY KEY
   , name VARCHAR(100)
);
CREATE TABLE invoice (cust_no INTEGER
   , whn DATE
   , amt DECIMAL(10,2)
   ,FOREIGN KEY(cust_no) REFERENCES customer(id));
Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense