79637

79637



Using Foreign Keys

In MySQL, innoDB tables support checking of foreign key constraints. See Section 14.2, “The InnoDB

Storage Engine”, and Section 1.8.5.4, “Foreign Key Differences".

A foreign key constraint is not required merely to join two tables. For storage engines other than

InnoDB, it is possible when defining a column to use a REFERENCES tbl_name {col_name} clause,

which has no actual effect, and serves only as a memo orcomment to you that the column which

you are currently defining is intended to refer to a column in another table. It is extremely important to realize when using this syntax that:

•    MySQL does not perform any sort of CHECK to make surę that col_name actually exists in

tbl_name (or even that tbl_name itself exists).

•    MySQL does not perform any sort of action on tbl_name such as deleting rows in response to

actions taken on rows in the table which you are defining; in other words, this syntax induces no

on delete or on update behavior whatsoever. (Although you can write an on delete or on

UPDATE clause as part of the REFERENCES clause, it is also ignored.)

•    This syntax creates a column; it does not create any sort of index or key.

You can use a column so created as a join column, as shown here:

CREATE TABLE person (

id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, name CHAR(60) NOT NULL,

PRIMARY KEY (id)

) ;

CREATE TABLE shirt (

id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, style ENUM('t-shirt', 'polo', 'dress') NOT NULL, color ENUM('red', 'blue', 'orange', 'white', 'black') NOT NULL, owner SMALLINT UNSIGNED NOT NULL REFERENCES person(id),

PRIMARY KEY (id)

);

INSERT INTO person YALUES (NULL, 'Antonio Paz');



Wyszukiwarka

Podobne podstrony:
Node j ssupport. MySQL Cluster NDB 7.3 also supports applications written in JavaScript using Node.j
tabela2 mysql> show tables; H----------------------^
Futurę InnoDB File Formats The file format used by the standard built-in InnoDB in MySQL 5.1 is the
InnoDB Data Storage and Compression Ali user data in InnoDB tables is stored in pages comprising a B
InnoDB Notes For InnoDB tables, be careful if you modify the column containing the auto-increment va
Using Client Programs in a MultipleServer Environment To connect with a Client program to a MySQL se
SQL nodes. If you compile MySQL with clustering support, and perform the default installation (using
Unsupported or Missing Features in MySQL Cluster A number of features supported by other storage eng
InnoDB Data Storage and Compression Ali user data in InnoDB tables is stored In pages comprising a B
f4 12 Create Foreign Key ZTXLFA1 -REGIO Short text Use the ualues in ztxlfa1cc to ualidate landl
f4 3 Create Foreign Key ZTXLFA1-LAND1 Short text Using ztxt005 to ualidate
skanowanie0107 (2) 12.4.5.    Keys to teaching the writing skills A number of things
skan8 Ironson G. i in. (1993, August), Social support, neuroendocrine, and immune functioningduring
skanowanie0107 (2) 12.4.5.    Keys to teaching the writing skills A number of things
skanowanie0107 (2) 12.4.5.    Keys to teaching the writing skills A number of things
mus dev(7) 36 192 Miner*a St., Derby, Conn. DEAR SIR: ... I ara using scven cables in one of my exer
Obraz5 (97) a Oescribe the items In the photos using fhe words In the box. ieather porcelain denim

więcej podobnych podstron