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

regarding foreign key

147 100+
Hi,
I cant able to create an table with a foreign key :

Syntax :

Expand|Select|Wrap|Line Numbers
  1. create table order(orderid int not null,cost int,cid int not null,foreign key(cid) references customer(cid))type=innodb;
  2.  
Here customer is the other table.


Error Msg:
ERROR 1064 (42000) : you have an error in your sql syntax ;check the manual that corresponds to your MYSQL server version for the right syntax...........


thanks....
Jan 21 '10 #1
5 1865
Atli
5,058 Expert 4TB
Hi.

Please post the entire error message. You cut it of just before the part where it explain what was causing the error.

Incidentally, you might want to read the entire error messages more thoroughly. This error, for instance, tells you exactly where the error occurred, so that you can review that part of the query and look up the proper syntax.
Jan 21 '10 #2
dgreenhouse
250 Expert 100+
Your initial error is with naming a table "order."

order is a reserved word and must be encapsulated in back-ticks if used.
i.e.
create table `order` (....

Also, it's best to create tables with plurals if possible.
i.e
create table orders (...

This of course avoids needing back-ticks.

See: http://dev.mysql.com/doc/refman/5.0/...ved-words.html
Jan 21 '10 #3
santhanalakshmi
147 100+
hi,

Thanks a lot.......now i can able to create a table with the foreign key....as you told,thanks.

can you tell me the difference between :

create table order(........)

and

create table orders(.......)


reserved word means -> key word ah.
Jan 22 '10 #4
dgreenhouse
250 Expert 100+
The difference between the table names is: the table 'orders' - means that the table CONTAINS multiple orders. Whereas a table with the name 'order' would by definition mean it has 1 order in it. Subtle and obviously a table with the name 'order' with multiple records would mean it's an 'orders' table, but the standard naming convention for an 'orders' table is... You guessed it - "Orders!" :-)
Jan 22 '10 #5
santhanalakshmi
147 100+
hi,

thanks for ur response...i got the meaning.
Jan 22 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Jeremiah Jacks | last post by:
I just upgraded to MySQL 4.0.14-standard for RedHat Linux and am using = the pre-compiled binaries. I have a database with INNODB tables. When I insert a row into one of the child tables, I get...
2
by: geoff | last post by:
The table creation script(at the end of this post) works fine on 4.0.1-alpha-win, but the foreign key constraints fail on 4.0.15-win. I am starting the server with the same command for both...
1
by: J Belly | last post by:
Hi, all: I'm a newbie trying to understand the concept of referential integrity and dealing with Primary and Foreign Keys. I'm sure mine is a simple problem... I've created 3 tables as...
10
by: Bodza Bodza | last post by:
I'm having an argument with an incumbent self-taught programmer that it is OK to use null foreign keys in database design. My take is the whole point of a foreign key is that it's not supposed...
31
by: Robert Brown | last post by:
Let's say I have a type hierarchy: (just an example) the general entity customer: CREATE TABLE customer(customer_id int, customer_name varchar(250), customer_type int) three specific...
0
by: Scott Ribe | last post by:
I've got a problem which I think may be a bug in Postgres, but I wonder if I'm missing something. Two tables, A & B have foreign key relations to each other. A 3rd table C, inherits from A. A...
3
by: razheev | last post by:
Hi, I am doing a purge process and trying to delete rows .Let me know how efficiently I can handle the purge process because of the RI on the tables. TABLE A is a PARENT of TABLE B, TABLE C,...
10
by: Shawn Chisholm | last post by:
Hi, I am trying to deal with a deadlock situation caused by foreign key references on insert and I was wondering if anyone knows what order the foreign keys are locked (or evaluated) in for a...
1
by: muralik | last post by:
Hi all, I want to refer to a foreign key in a table and set null on delete and on update cascade it...my commands were as follows.. create table Institute( name ...
1
by: bg_ie | last post by:
I'm designing a database with 3 tables called Function, Test and Scene. A Function has multiple Tests, but a Test has only one Function. A many to many relationship exists between Test and Scene...
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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.