0

Hello i am curently trying to set up a data base in MYSQL and i want to have my Varchar element as the Primary Key but it always gives me an error like this:

Invalid use of NULL value

the command i am using is:

ALTER  TABLE temp_keys ADD PRIMARY KEY (temp_key);

and here is how the table is set up:

Intel

I hope that some one of you can help me with this.

  • 1
    Does this answer your question? [NULL value in multi-column primary key](https://stackoverflow.com/questions/11001333/null-value-in-multi-column-primary-key) – P.Salmon Apr 07 '22 at 07:11
  • 1
    Also PRIMARY KEY A unique index where all key columns must be defined as NOT NULL - https://dev.mysql.com/doc/refman/8.0/en/create-table.html – P.Salmon Apr 07 '22 at 07:15

1 Answers1

0

VARCHAR data type is not a problem. PRIMARY KEY columns must be defined as NOT NULL. Append CHANGE temp_key temp_key VARCHAR (50) NOT NULL in your query and change value(50) according to your need.

Just execute ALTER TABLE temp_keys CHANGE temp_key temp_key VARCHAR (50) NOT NULL, ADD PRIMARY KEY (temp_key); result

Md. Al Amin Bhuiyan
  • 303
  • 1
  • 3
  • 12