mysql> CREATE DATABASE testfk;
Query OK, 1 row affected (0.00 sec)
mysql> \u testfk
Database changed
mysql> CREATE TABLE t1
-> (
-> f1 VARCHAR(10) NOT NULL PRIMARY KEY
-> );
Query OK, 0 rows affected (0.01 sec)
mysql> INSERT INTO t1 VALUES
-> ('bla-bla');
Query OK, 1 row affected (0.00 sec)
mysql> CREATE TABLE t2
-> (
-> id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
-> f2 VARCHAR(10) NOT NULL
-> );
Query OK, 0 rows affected (0.02 sec)
mysql> ALTER TABLE t2
-> ADD FOREIGN KEY (f2) REFERENCES t1 (f1)
-> ON UPDATE RESTRICT
-> ON DELETE RESTRICT;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> DESCRIBE t1;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| f1 | varchar(10) | NO | PRI | NULL | |
+-------+-------------+------+-----+---------+-------+
1 row in set (0.00 sec)
mysql> DESCRIBE t2;
+-------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| f2 | varchar(10) | NO | MUL | NULL | |
+-------+------------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
mysql> INSERT INTO t2 VALUES (NULL,'bla-bla');
Query OK, 1 row affected (0.01 sec)
mysql> SELECT * FROM t1;
+---------+
| f1 |
+---------+
| bla-bla |
+---------+
1 row in set (0.00 sec)
mysql> SELECT * FROM t2;
+----+---------+
| id | f2 |
+----+---------+
| 1 | bla-bla |
+----+---------+
1 row in set (0.00 sec)
почти все люди одинаковые и думают почти одинаково.Какая прелесть.