2

I add this line for add ignore to MySql database :

ALTER IGNORE cms_books_author name ADD UNIQUE(name)

but I get this error:

Error
SQL query:


ALTER IGNORE cms_books_author name ADD UNIQUE(name)
MySQL said: Documentation

#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 'efcms_books_author name ADD UNIQUE(name)' at line 1 

Mysql version is : 5.6.20

how do I fix this error? Thank you.

DirtyBit
  • 16,613
  • 4
  • 34
  • 55
Perspolis
  • 862
  • 3
  • 11
  • 28

1 Answers1

1

syntax issues

  1. alter ignore missing the table keyword
  2. syntax should only include the name within the unique index not after the tablename

adjusted

ALTER IGNORE table cms_books_author ADD UNIQUE(name);

sqlfiddle


alter table syntax

ALTER [ONLINE | OFFLINE] [IGNORE] TABLE tbl_name
    [alter_specification [, alter_specification] ...]
    [partition_options]

...

alter_specification:
    table_options
  | ADD [CONSTRAINT [symbol]]
        UNIQUE [INDEX|KEY] [index_name]
        [index_type] (index_col_name,...) [index_option] ...
Community
  • 1
  • 1
amdixon
  • 3,814
  • 8
  • 25
  • 34