Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

foreign key 1

Status
Not open for further replies.

bobthesnake77

Programmer
Joined
Apr 15, 2003
Messages
3
Location
CH
Hello,

I'm trying to build a db with foreign keys, I'm using mysql 3.23.39, here's what I did:

CREATE TABLE persons (
id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
name CHAR(60) NOT NULL,
PRIMARY KEY (id)
);

CREATE TABLE shirts (
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 persons,
PRIMARY KEY (id)
);

But when I insert a shirt with an owner that doesn't exist or when I delete a person which still has shirts, I can do (I shouldn't!!!)

Can someone help me with that??? Thanks...
 
Ok thanks, but is the syntax correct at least???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top