Search code examples
mysqlsqlcreate-table

MySQL - Error: Missing right parenthesis


I'm trying to create a new table called SITANAG with SQLTalk for Window. When i execute this command:

CREATE TABLE SITANAG
(
   ANAGCOD INT NOT NULL UNIQuE,
   PRIMARY KEY(ANAGCODE)
);

I get this error:

ANAGCOD INT NOT NULL UNIQUE,
                     ^
Error: Missing right parenthesis

Someone know why this give error?

Thank for your time


Solution

  • You dont have to make the column as NOT NULL and UNIQUE explicitly. Primary key is by default NOT NULL and UNIQUE. Try this:

    CREATE TABLE SITANAG
    (
       ANAGCOD  INT, 
       PRIMARY KEY(ANAGCOD )
    );
    

    DEMO

    On a side note you have a typo error when you are naming your column in primary key, it should be either ANAGCOD or ANAGCODE

    The manual says:

    A PRIMARY KEY is a unique index where all key columns must be defined as NOT NULL. If they are not explicitly declared as NOT NULL, MySQL declares them so implicitly (and silently).