Equivalent of MSSQL IDENTITY Column in MySQL

What is the equivalent of MSSQL IDENTITY Columns in MySQL? How would I create this table in MySQL?

CREATE TABLE Lookups.Gender
(
    GenderID   INT         IDENTITY(1,1) NOT NULL,
    GenderName VARCHAR(32) NOT NULL
);

Answers


CREATE TABLE Lookups.Gender
(
    GenderID   INT         NOT NULL AUTO_INCREMENT,
    GenderName VARCHAR(32) NOT NULL
);

CREATE TABLE `Persons` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `LastName` varchar(255) NOT NULL,
  `FirstName` varchar(255) DEFAULT NULL,
  `Address` varchar(255) DEFAULT NULL,
  `City` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=100 DEFAULT CHARSET=latin1;

This above example uses the AUTO_INCREMENT syntax. You can specify a starting offset specific to the table.

The Increment, however, has to be set globally.

SET @@auto_increment_increment=10;

You can also set a global default for the offset like follows:

SET @@auto_increment_offset=5;

To view your current values, type SHOW VARIABLES LIKE 'auto_inc%';


Need Your Help

EditText OnKeyListener not working

android android-edittext keylistener

I know this/similar question has been asked before but the solution given is not working for me so I'm asking again.

Why is my JQuery selector returning a n.fn.init[0], and what is it?

jquery jquery-selectors

I have a set of dynamically generated checkboxes, where each of them has a data-id attribute corresponding to a database integer id. When i populate my html-form with an object to edit, there is a ...