How to generate mysql primary key id (self-increment, unique and irregular)

How to generate mysql primary key id (self-increment, unique and irregular)

1. Use the uuid function to generate a unique and irregular primary key id

sql:

CREATE TABLE `test` (
  `id` varchar(100) COLLATE utf8_estonian_ci NOT NULL COMMENT 'Unique and non-duplicate',
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `sex` int(11) DEFAULT NULL,
  `name` varchar(255) COLLATE utf8_estonian_ci DEFAULT NULL,
  `username` varchar(255) COLLATE utf8_estonian_ci DEFAULT NULL,
  `password` varchar(255) COLLATE utf8_estonian_ci DEFAULT NULL,
  `classes` varchar(255) COLLATE utf8_estonian_ci DEFAULT NULL,
  `major` int(255) DEFAULT NULL,
  `QQ` int(20) DEFAULT NULL,
  `introducemyself` varchar(255) COLLATE utf8_estonian_ci DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_estonian_ci ROW_FORMAT=DYNAMIC;

surface:

Insert statement:

INSERT INTO test(id,sex,name,username,password,classes,major,QQ,introducemyself) VALUE(replace(uuid(), '-', ''),1,"小米","xck","001","班八",265,953190259,"我最牛");

Executed twice, generating two different ids:

2. Automatic growth of id

Change the type to integer and select auto-growth below

See DDL:

CREATE TABLE `test` (
  `id` bigint(100) NOT NULL AUTO_INCREMENT COMMENT 'unique and non-duplicate',
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `sex` int(11) DEFAULT NULL,
  `name` varchar(255) COLLATE utf8_estonian_ci DEFAULT NULL,
  `username` varchar(255) COLLATE utf8_estonian_ci DEFAULT NULL,
  `password` varchar(255) COLLATE utf8_estonian_ci DEFAULT NULL,
  `classes` varchar(255) COLLATE utf8_estonian_ci DEFAULT NULL,
  `major` int(255) DEFAULT NULL,
  `QQ` int(20) DEFAULT NULL,
  `introducemyself` varchar(255) COLLATE utf8_estonian_ci DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_estonian_ci ROW_FORMAT=DYNAMIC;

Insert a piece of data, sql:

INSERT INTO test(sex,name,username,password,classes,major,QQ,introducemyself) VALUE(1,"小米","xck","001","班八",265,953190259,"我最牛");

Corresponding database changes:

This is the end of this article about how to generate MySQL primary key ID (self-increment, unique and irregular). For more relevant MySQL primary key ID generation content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Summary of how to generate the primary key of sqlserver database (sqlserver,mysql)

<<:  The iframe frame sets the white background to transparent in IE browser

>>:  How to inherit CSS line-height

Recommend

Docker uses root to enter the container

First run the docker container Run the command as...

mysql 5.7.23 winx64 decompression version installation tutorial

Detailed installation tutorial of mysql-5.7.23-wi...

In-depth understanding of MySQL slow query log

Table of contents What is the slow query log? How...

Node uses koa2 to implement a simple JWT authentication method

Introduction to JWT What is JWT The full name is ...

Docker container from entry to obsession (recommended)

1. What is Docker? Everyone knows about virtual m...

Detailed tutorial on distributed operation of jmeter in docker environment

1. Build the basic image of jmeter The Dockerfile...

HTML table markup tutorial (2): table border attributes BORDER

By default, the border of the table is 0, and we ...

Use label tag to select the radio button by clicking the text

The <label> tag defines a label (tag) for an...

HTML+CSS implementation code for rounded rectangle

I was bored and suddenly thought of the implementa...

jQuery canvas generates a poster with a QR code

This article shares the specific code for using j...

Introduction to HTML basic controls_PowerNode Java Academy

The <input> tag The <input> tag is us...

Detailed explanation of the life cycle of Angular components (Part 2)

Table of contents 1. View hook 1. Things to note ...

Basic tutorial on controlling Turtlebot3 mobile robot with ROS

Chinese Tutorial https://www.ncnynl.com/category/...

The most convenient way to build a Zookeeper server in history (recommended)

What is ZooKeeper ZooKeeper is a top-level projec...