0

I am new to MySql and am using Workbench.

I am confused over the checkboxes PK, NN, UQ, AI and G.

Wouldn't a Primary Key mean it must be not null and unique? So why allow a Primary Key that does not have to be unique?

Wouldn't Auto Increment mean it must be Generated? The checkboxes in the upper half of the window treat AI and G like radio buttons, checking one uncheck the other. However, the Auto Increment and Generated checkboxes at the bottom half of the window behave differently where Auto Increment is always disabled. Do the acronyms mean what I think they mean?

What settings should I use if I want a column to contain an automatically generated unique int vaue, like the Identity attribute in Microsoft Sql?

Old Geezer
  • 14,854
  • 31
  • 111
  • 198
  • See [difference between PK and Unique keys](https://stackoverflow.com/questions/6379954/difference-between-unique-key-and-primary-keys). A unique key is a secondary key and a primary key the main clustered index (having unique NN properties. [Generated](https://dev.mysql.com/doc/refman/5.7/en/create-table-secondary-indexes.html) columns are a new concept meaning derived from other columns and very different from the inbuilt AI. – danblack Dec 03 '18 at 04:45

1 Answers1

0

For an AI unique value:

CREATE TABLE tbl (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY
)

The primary key for all indexing purposes is the same as a unique key.

danblack
  • 12,130
  • 2
  • 22
  • 41