Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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


1 Answers

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).

like image 163
Rahul Tripathi Avatar answered Aug 26 '26 22:08

Rahul Tripathi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!