This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes MySQL code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "MySQL code" Watch "MySQL code" New topic

MySQL code

Nanuim Ud

Joined: Jun 17, 2013
Posts: 3

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` (
`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

Joined: Mar 22, 2005
Posts: 42958
Welcome to JavaRanch. According to, such constraints need to be inside the parentheses.
I agree. Here's the link:
subject: MySQL code
It's not a secret anymore!