1

I just want to have a table in which a first column is a monotonically increasing unique integer number. For example, if I have a table with 5 rows the indexes of the rows should be 1,2,3,4,5. And if I add a new row it gets index 6.

I am alway confused with this things because there are many related options: "auto_increment", "primary key", "unique", "index". What should I use?

yagmoth555
  • 17,495
Roman
  • 2,739
  • 10
  • 34
  • 33

1 Answers1

2
CREATE TABLE test (
     id INT NOT NULL AUTO_INCREMENT,
     name CHAR(30) NOT NULL,
     PRIMARY KEY (id)
 );

auto_increment: This value will automatically increase.

primary key: This is the column which holds the first, and probably most logical, sort order. Almost always this means that it's unique.

index: This column is one which might be chosen as a sort order. Any column or combination of columns can be indexed, not just the primary key.

unique: This is a special index, where each value is going to appear only once.

gorilla
  • 1,217