0

I am trying to create these two tables for a simple script I downloaded but when running the sql command it returns a syntax error.

The error I get is:

CREATE TABLE `usrsig` (
  `id` int(9) NOT NULL auto_increment,
  `url` varchar(255) default NULL,
  `user` int(9) NOT NULL default '0',
  PRIMARY KEY  (`id`)
  KEY `user_own` (`user`) 
);

#1064 - 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 'KEY `user_own` (`user`) )' at line 6

And the following for the 2nd tabel:

CREATE TABLE `usruser` (
  `id` int(9) NOT NULL auto_increment,
  `name` varchar(30) NOT NULL default '',
  `pass` varchar(30) default NULL,
  `last` datetime default NULL,
  `hits` int(9) NOT NULL default '0',
  PRIMARY KEY  (`id`)
  KEY `name_index` (`name`) 
);

#1064 - 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 'KEY `name_index` (`name`) )' at line 8

If anyone could be so kind as to help me out I would be greatly appreciative.

Thanks

5 Answers 5

2

You're just missing a comma after PRIMARY KEY (id)

CREATE TABLE `usrsig` (
  `id` int(9) NOT NULL auto_increment,
  `url` varchar(255) default NULL,
  `user` int(9) NOT NULL default '0',
  /* Comma needed... */
  PRIMARY KEY  (`id`),
  KEY `user_own` (`user`) 
);


CREATE TABLE `usruser` (
  `id` int(9) NOT NULL auto_increment,
  `name` varchar(30) NOT NULL default '',
  `pass` varchar(30) default NULL,
  `last` datetime default NULL,
  `hits` int(9) NOT NULL default '0',
  /* Comma needed... */
  PRIMARY KEY  (`id`),
  KEY `name_index` (`name`) 
);

As a tip, about 99% of the time, the error as reported by MySQL occurs exactly one character before the place identified. So look one character or symbol before KEY name_index:

check the manual that corresponds to your MySQL server version for the right syntax to use near 'KEY name_index

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much 100% spot on. Sorry only got to answer now but system never informed me of answer to my post. Thanks again
@BarrySchulman Welcome to Stack Overflow. Unlike other forums and things, answers here come within mintes or seconds of asking questions for all but the most esoteric things. So next time check back right away. We'll help out and send you along on your way :)
0

I think you are just missing a comma after the PRIMARY KEY ('id') line.

Comments

0

The way you are putting Primary key and other key is the syntax problem.

Primary Key (id),

Put a comma after this.

Comments

0
CREATE TABLE usrsig (
  id int(9) NOT NULL  AUTO_INCREMENT,
  url varchar(255) DEFAULT NULL,
  user int(9) NOT NULL DEFAULT 0,
  PRIMARY KEY  (id),
  KEY user_own (user) 
);

CREATE TABLE usruser (
  id int(9) NOT NULL  AUTO_INCREMENT,
  name varchar(30) NOT NULL DEFAULT '',
  pass varchar(30) DEFAULT NULL,
  last datetime DEFAULT NULL,
  hits int(9) NOT NULL DEFAULT 0,
  PRIMARY KEY  (id),
  KEY name_index (name) 
);

Comments

0

Any primary key error - fix

//delete all

  1. Drop-Database

  2. Remove-Migration

  3. Remove-Migration

  4. Remove-Migration until you clear all migration

  5. Add-Migration

  6. Update-Database

success

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.