Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MySQL code

 
Nanuim Ud
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Could someone please assist me point out the error in this sql statement below.
I have created a table "sunnettable" and I am trying to create the table "dailyactivity" and link it to the first table

CREATE TABLE `dailyactivity` (
`da_id` INT(10) UNSIGNED NOT NULL,
`employee_id` Varchar(10) NOT NULL,
`report_date` date NOT NULL,
`client_details` VARCHAR(255),
`assignment` VARCHAR(255),
`resolutions` VARCHAR(255),
`comments` VARCHAR(255),
PRIMARY KEY (`da_id`))
CONSTRAINT fk_sunnettable FOREIGN KEY (employee_id) REFERENCES sunnettable (employee_id)

This is the error I'm getting:

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 'CONSTRAINT fk_sunnettable FOREIGN KEY (employee_id) REFERENCES sunnettable (empl' at line 10

I'll really appreciate any help!
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch. According to http://dev.mysql.com/doc/refman/5.1/en/create-table.html, such constraints need to be inside the parentheses.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic