Reputation: 95
I am getting an error saying there is a syntax error in this code,
CREATE TABLE IF NOT EXISTS `reportcategorys` (
`categoryName` varchar(100) NOT NULL,
`subCategoryName` varchar(500) NOT NULL,
PRIMARY KEY (`categoryName`),
FOREIGN KEY (`subCategoryName`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `reportsubcategorys` (
`subCategoryName` varchar(500) NOT NULL,
`categoryName` varchar(100) NOT NULL,
PRIMARY KEY (`subCategoryName`),
FOREIGN KEY `Category_Name` (`categoryName`)
)ENGINE=InnoDB DEFAULT CHARSET=latin1;
I can't see the syntax error
Upvotes: 0
Views: 32
Reputation: 651
while describing Foreign key you need to write like
FOREIGN KEY(subCategoryName) REFERENCES reportcategory(categoryName)
for more information check this
https://dev.mysql.com/doc/refman/5.6/en/create-table-foreign-keys.html
Upvotes: 1
Reputation: 308938
What does that FOREIGN KEY point to? No table that I can see.
The syntax ought to look like
FOREIGN KEY(subCategoryName) REFERENCES reportcategory(categoryName)
Substitute the table and its primary key as needed.
Table name ought to be singular: reportCategory
, not reportCategories
. (Style preference, not syntax.)
Upvotes: 3