Jump to content

[SOLVED] foreign key problem


zed420

Recommended Posts

Hi All

Can some one please tell me what is wrong with these two tables that I've created each time I'm dropping them into database this error keeps coming up; #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FOREIGN KEY (user_id) REFERENCES user(id)

) ENGINE=MyISAM  DEFAULT CHARSET=lat' at line 30

 

 

DROP TABLE user;

CREATE TABLE `user` (

  `id` smallint(5) unsigned NOT NULL auto_increment,

  `fullname` varchar(60) NOT NULL,

  `username` char(15) NOT NULL,

  `pswd` char(32) NOT NULL,

  `address` varchar(70) NOT NULL,

  `post_code` varchar(10) NOT NULL,

  `tel` int(11) NULL,

  `mobile` char(40) NOT NULL,

  `email` char(55) NOT NULL,

  `profile` char(255) NOT NULL, 

  PRIMARY KEY  (`id`));

 

DROP TABLE job_tb;

 

CREATE TABLE `job_tb` (

  `job_id` tinyint(4) NOT NULL auto_increment,

  `user_id` int default NULL,

  `typeOfbooking` char(10) default NULL, 

  `typeOfcustomer` char(10) default NULL,

  `typeOfvehicle` char(20) default NULL,

  `noOfVehicle` char(10) default NULL,

  `regul` char(20) default NULL,

  `mon` char(5) default NULL,

  `tue` char(5) default NULL,

  `wed` char(5) default NULL,

  `thur` char(5) default NULL,

  `fri` char(5) default NULL,

  `sat` char(5) default NULL,

  `sun` char(5) default NULL,

  `cust_name` varchar(40) NOT NULL,

  `cust_address` varchar(60) NOT NULL,

  `post_code` varchar(12) default NULL,

  `cust_tel` int(11) NOT NULL,

  `email` varchar(60) NOT NULL,

  `des` varchar(50) NOT NULL,

  `reqVehicle` char(10) default NULL,

  `dateDay` tinyint(2) default NULL,

  `dateMO` tinyint(12) default NULL,

  `dateYr` mediumint(5) default NULL,

  `timeHr` tinyint(2) default NULL,

  `timeMin` tinyint(2) default NULL,

  `comment` varchar(255) default NULL,

  PRIMARY KEY  (`job_id`)

  FOREIGN KEY (user_id) REFERENCES user(id)

) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ;

 

Thanks

Zed

 

Link to comment
https://forums.phpfreaks.com/topic/128674-solved-foreign-key-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.