473,382 Members | 1,648 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,382 software developers and data experts.

mysql requires field names of referenced keys to be specified explicitly

Hello,

Consider the following PostgreSQL or Oracle SQL DDL code:

CREATE TABLE fooTable (
foo INTEGER,
PRIMARY KEY (foo)
);

CREATE TABLE barTable (
bar INTEGER,
foo INTEGER,
PRIMARY KEY (bar),
FOREIGN KEY (foo) REFERENCES fooTable
);

When the same code is run against MySQL 4.1 the following error is output:

ERROR 1005 (HY000): Can't create table '.\foobar\bartable.frm' (errno: 150)

The reason is that MySQL 4.1 seems to require the names of referenced fields
in the referenced table to be specified even when their names are the same as
ones in the referencing table. Here is how the problem is fixed on MySQL 4.1:

CREATE TABLE barTable (
bar INTEGER,
foo INTEGER,
PRIMARY KEY (bar),
FOREIGN KEY (foo) REFERENCES fooTable (foo)
);

I wonder whether there are plans for future versions of MySQL to relax this
restriction in an attempt to better comply with other RDBMSs' syntax.

Thanks,

Neil
Jul 23 '05 #1
1 1575
Neil Zanella wrote:
The reason is that MySQL 4.1 seems to require the names of referenced fields
in the referenced table to be specified even when their names are the same as
ones in the referencing table. Here is how the problem is fixed on MySQL 4.1:

CREATE TABLE barTable (
bar INTEGER,
foo INTEGER,
PRIMARY KEY (bar),
FOREIGN KEY (foo) REFERENCES fooTable (foo)
);
For what it's worth, the following works for me (in MySQL 5.0.2):

CREATE TABLE barTable (
bar INTEGER,
foo INTEGER REFERENCES fooTable,
PRIMARY KEY (bar)
);

But the constraint syntax you were trying still fails in 5.0.2, as you
found it does in MySQL 4.1.
I wonder whether there are plans for future versions of MySQL to relax this
restriction in an attempt to better comply with other RDBMSs' syntax.


I don't think anyone on this newsgroup can answer that.

Regards,
Bill K.
Jul 23 '05 #2

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

Similar topics

3
by: 'bonehead | last post by:
Greetings, I'd like to figure out some syntax for retrieving the data from a table when I don't know all the of field names. What I do know are, the name of the table, the names of the primary...
3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
0
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been released. It is now available in source and binary...
0
by: Chris | last post by:
Hi, I am currently designing a simple service orders database. I have played around with MySQL a bit but this is the first time I'm using it in anger, I have a few design queries to make sure I am...
1
by: Good Man | last post by:
Hi there I've noticed some very weird things happening with my current MySQL setup on my XP Laptop, a development machine. For a while, I have been trying to get the MySQL cache to work....
0
by: NewbieSupreme | last post by:
I'm using PHPMyAdmin on an Apache2Triad install (latest version; 5.x.x, which installs PHP5 and PHPMyAdmin 2.8 as well). In Access, I exported a table to a text file, tab-delimited, text qualifyer...
13
by: S.Dickson | last post by:
I had an access database that i use as an ordering system. I have a form for entering customer details. When i add a new customer on the form the customer number is an auto number that appears when...
6
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get...
1
ssnaik84
by: ssnaik84 | last post by:
Hi Guys, Last year I got a chance to work with R&D team, which was working on DB scripts conversion.. Though there is migration tool available, it converts only tables and constraints.. Rest of...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.