Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the standard way to determine the number for a primary key?

I'm planning to make a very simple program using php and mySQL. The main page will take information and make a new row in the database with that information. However, I need a number to put in for the primary key. Unfortunately, I have no idea about the normal way to determine what umber to use. Preferably, if I delete a row, that row's key won't ever be reused.

A preliminary search has turned up the AUTOINCREMENT keyword in mySQL. However, I'd still like to know if that will work for what I want and what the common solution to this issue is.

like image 938
Eugene M Avatar asked Nov 28 '22 06:11

Eugene M


1 Answers

In MySQL that's the standard solution.

CREATE TABLE animals (
     id MEDIUMINT NOT NULL AUTO_INCREMENT,
     name CHAR(30) NOT NULL,
     PRIMARY KEY (id)
 );
like image 91
Vinko Vrsalovic Avatar answered Nov 30 '22 23:11

Vinko Vrsalovic