MySQl help plzzzzzzz

Discussion of programming on Linux, including shell scripting, perl, python, c/c++, mono, java. Whatever tickles your fancy.

MySQl help plzzzzzzz

Postby woundedtiger » Sat Aug 20, 2005 1:34 am

bro i have problem in mysql plz help me i want to create a foreign key in one table which is primary key in other table i use InnoDB for that but still some time the query passed but constraint not apply and some thing i got error or query here what i am doing please not i already set up InnoDb

creating first table

CREATE TABLE head (
head_code int(11) NOT NULL default '0',
head_name varchar(30) default NULL,
PRIMARY KEY (head_code),
UNIQUE KEY head2 (head_code),
UNIQUE KEY head3 (head_name),
KEY head1 (head_code)
) TYPE=InnoDB;

creating 2nd table
CREATE TABLE sub (
sub_code int(11) NOT NULL default '0',
sub_name varchar(30) default NULL,
head_code int(11) NOT NULL default '0',
PRIMARY KEY (sub_code),
UNIQUE KEY sub3 (sub_name),
UNIQUE KEY sub2 (sub_code),
KEY sub1 (head_code),
KEY sub11 (sub_code),
FOREIGN KEY (`head_code`) REFERENCES `agritec1.head` (`head_code`)
) TYPE=InnoDB;


here the primary key column of HEAD table "head_code" should be the foreign key in 2nd table SUB same as "head_Code"

if i pass value in sub like (1,"as"2) it accept where as in head the "2" value in head_Code column not present .
but still accepted.so no constraint apply
This is the error i received

ERROR 1005: Can't create table '.\ag\sub.frm' (errno: 150)


pzl help meee
woundedtiger
Cadet
 
Posts: 14
Joined: Wed Oct 01, 2003 10:47 am

Postby saquib_javed » Sat Aug 20, 2005 11:42 am

my friend (google) gave me the following suggestion

http://www.google.com/search?q=%22ERROR ... 8&oe=utf-8
Use Linux and feel Free.
OR
Feel free to use Linux. ;)
saquib_javed
Naib Subedar
 
Posts: 344
Joined: Sat Apr 10, 2004 9:07 pm
Website: http://www17.brinkster.com/saquibjaved
Location: Karachi


Return to “%s” Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron