File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC 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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "MySQL code" Watch "MySQL code" New topic
Author

MySQL code

Nanuim Ud
Greenhorn

Joined: Jun 17, 2013
Posts: 3
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
Marshal

Joined: Mar 22, 2005
Posts: 41087
    
  43
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.


Ping & DNS - my free Android networking tools app
 
 
subject: MySQL code
 
Similar Threads
Hibernate tool code generation org.hibernate.MappingException: Foreign key
Glassfish + jdbcrealm
if table has reference ,then could i put refered table with refering table seperately
MySQL syntax error when importing from mysql_db_struct.sql
Hypersonic DB question