473,322 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

REFERENCES question in mySQL 4.1

I have two questions about REFERENCES:

1. It appears that mySQL treats REFERENCES associated with an
attribute differently than FOREIGN KEY (<blah>) REFERENCES...
Specifically, the first form does not appear to work, while the later
does. Here's a simple example (slightly edited):

mysql> CREATE TABLE person (id char(5) primary key);
Query OK, 0 rows affected (0.04 sec)

mysql> CREATE TABLE phone (id char(5) not null REFERENCES person(id),
num char(10) not null, PRIMARY KEY (id, num));
Query OK, 0 rows affected (0.06 sec)

mysql> show create table phone;
| phone | CREATE TABLE `phone` (
`id` char(5) NOT NULL default '',
`num` char(10) NOT NULL default '',
PRIMARY KEY (`id`,`num`)
) TYPE=InnoDB CHARSET=latin1 |
1 row in set (0.00 sec)

mysql> insert into phone value ('foo', 'bar');
Query OK, 1 row affected (0.04 sec)

It appears that the constraint is not created and is certainly not
enforced. Now consider what should be the same phone table.

mysql> drop table phone;
Query OK, 0 rows affected (0.29 sec)

mysql> CREATE TABLE phone (id char(5) not null, num char(10) not null,
PRIMARY KEY (id, num), FOREIGN KEY (id) REFERENCES person(id));
Query OK, 0 rows affected (0.09 sec)

mysql> show create table phone;
| Table | Create Table
| phone | CREATE TABLE `phone` (
`id` char(5) NOT NULL default '',
`num` char(10) NOT NULL default '',
PRIMARY KEY (`id`,`num`),
FOREIGN KEY (`id`) REFERENCES `person` (`id`)
) TYPE=InnoDB CHARSET=latin1 |
1 row in set (0.00 sec)

mysql> insert into phone values ('foo', 'bar');
ERROR 1216: Cannot add or update a child row: a foreign key constraint
fails

Why are these different?

2. In the manual (and in several posts), it clearly states (see
Section 7.5.4.2 of the 4.1.0-alpha manual)

"Both tables have to be InnoDB type and there must be an index where
the foreign key and the referenced key are listed as the FIRST
columns"

However, I did not create an indicies, but it worked. What's up?

Thanks in advance
Jul 19 '05 #1
0 1464

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: francescomoi | last post by:
Hi. I'm trying to build 'MySQL-python-1.2.0' on my Linux FC2: ---------------------------------- # export PATH=$PATH:/usr/local/mysql/bin/ # export mysqlclient=mysqlclient_r # python setup.py...
0
by: Randell D. | last post by:
Folks, I have installed MySQL v4 (client, server and development rpm's). I've tried and failed to use the recommended mysqladmin to set a root password after the installation (I have another post...
0
by: Ed Smith | last post by:
I have two questions about REFERENCES: 1. It appears that mySQL treats REFERENCES associated with an attribute differently than FOREIGN KEY (<blah>) REFERENCES... Specifically, the first form...
4
by: mikey | last post by:
Hi all, I'm having great problems trying to install the latest MySQl RPM package onto my Red Hat Linux OS. There is already MySQL v 3.0 pre-installed with the RH Linux distribution disk but I...
5
by: MLH | last post by:
Cardinality? I hear it spoken of by MySQL users. Does it matter to MS Access if MySQL tables are attached via ODBC?
21
by: Karl O. Pinc | last post by:
FYI, It'd be nice if the error message from a REFERENCES constraint mentioned the column name into which the bad data was attempted to be inserted. In PostgreSQL 7.3: sandbox=> insert into...
2
by: trihanhcie | last post by:
I m currently working on a Unix server with a fedora 3 as an os My current version of mysql is 3.23.58. I'd like to upgrade the version to 5.0.18. After downloading from MYSQL.COM the package on...
1
by: manish deshpande | last post by:
Hi, When i'm installing MySQL-server-standard-5.0.24a-0.rhel3.i386.rpm by the following command: rpm -i MySQL-server-standard-5.0.24a-0.rhel3.i386.rpm the following error is being shown: ...
3
by: menzies | last post by:
Hi, I"m new to this forum, but I have been trying all day to install DBD::mysql onto my Intel MacBook. I've read lots of forums pages and none have gotten me to a successful 'make test' or a...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.