Link to home
Create AccountLog in
Avatar of curiouswebster
curiouswebsterFlag for United States of America

asked on

MySQL: I need to create a primary key on contact_id

I need to make contact_id a Primary key, unique and auto-incrementing. Could you provide me the script?

It seems, the phpMyAdmin panel may not have that ability to do all three. Plus, I prefer a script which I can save or later.

When I click MySQL's INSERT option, I see the wrong query created. (I did not insert a Default value, since I want that auto-generated.)

So, the INSERT option includes that contact_id field.

INSERT INTO `ps_contacts`(`contact_id`, `username`, `password`, `email`, `fname`, `lname`) VALUES ('[value-1]','[value-2]','[value-3]','[value-4]','[value-5]','[value-6]')

Please provide me the script which include that one field, contact_id, as a Primary key, unique and auto-incrementing.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Pavel Celba
Pavel Celba
Flag of Czechia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
You'll have syntax similar to this...

id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name CHAR(30) NOT NULL,

Open in new window


https://dev.mysql.com/doc/refman/8.0/en/integer-types.html provides the integer types you'll likely use.