• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

MySQL code

 
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!
 
Rancher
Posts: 43016
76
  • 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.
 
The problems of the world fade way as you eat a piece of pie. This tiny ad has never known problems:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic