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

Example code for implementing complex table headers in html table

Use HTML to create complex tables. Complex tables...

Detailed explanation of triangle drawing and clever application examples in CSS

lead Some common triangles on web pages can be dr...

MySQL log trigger implementation code

SQL statement DROP TRIGGER IF EXISTS sys_menu_edi...

Installation tutorial of mysql 8.0.11 compressed version under win10

This article shares the installation tutorial of ...

Detailed explanation of Object.create instance usage in js

1. Create a new object using the Object.create() ...

Install docker offline by downloading rpm and related dependencies using yum

You can use yum to install all dependencies toget...

The latest Linux installation process of tomcat8

Download https://tomcat.apache.org/download-80.cg...

HTML line spacing setting methods and problems

To set the line spacing of <p></p>, us...

MySQL uses SQL statements to modify table names

In MySQL, you can use the SQL statement rename ta...

A Deeper Look at SQL Injection

1. What is SQL injection? Sql injection is an att...

Solution to elementui's el-popover style modification not taking effect

When using element-ui, there is a commonly used c...

JavaScript implementation of carousel example

This article shares the specific code for JavaScr...

MySQL 8.0.21 installation tutorial under Windows system (illustration and text)

Installation suggestion : Try not to use .exe for...