Oracle 5.0 Reference Manual page 239

Table of Contents

Advertisement

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 VALUES (NULL, 'Antonio Paz');
SELECT @last := LAST_INSERT_ID();
INSERT INTO shirt VALUES
(NULL, 'polo', 'blue', @last),
(NULL, 'dress', 'white', @last),
(NULL, 't-shirt', 'blue', @last);
INSERT INTO person VALUES (NULL, 'Lilliana Angelovska');
SELECT @last := LAST_INSERT_ID();
INSERT INTO shirt VALUES
(NULL, 'dress', 'orange', @last),
(NULL, 'polo', 'red', @last),
(NULL, 'dress', 'blue', @last),
(NULL, 't-shirt', 'white', @last);
SELECT * FROM person;
+----+---------------------+
| id | name
+----+---------------------+
|
1 | Antonio Paz
|
2 | Lilliana Angelovska |
+----+---------------------+
SELECT * FROM shirt;
+----+---------+--------+-------+
| id | style
| color
+----+---------+--------+-------+
|
1 | polo
| blue
|
2 | dress
| white
|
3 | t-shirt | blue
|
4 | dress
| orange |
|
5 | polo
| red
|
6 | dress
| blue
|
7 | t-shirt | white
+----+---------+--------+-------+
SELECT s.* FROM person p INNER JOIN shirt s
ON s.owner = p.id
WHERE p.name LIKE 'Lilliana%'
AND s.color <> 'white';
+----+-------+--------+-------+
| id | style | color
+----+-------+--------+-------+
|
4 | dress | orange |
|
5 | polo
| red
|
6 | dress | blue
+----+-------+--------+-------+
When used in this fashion, the
or DESCRIBE:
TABLE
SHOW CREATE TABLE shirt\G
Using Foreign Keys
|
|
| owner |
|
1 |
|
1 |
|
1 |
2 |
|
2 |
|
2 |
|
2 |
| owner |
2 |
|
2 |
|
2 |
clause is not displayed in the output of
REFERENCES
219
SHOW CREATE

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents