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

W3C Tutorial (1): Understanding W3C

W3C, an organization founded in 1994, aims to unl...

MySQL 8.0.18 deployment and installation tutorial under Windows 7

1. Preliminary preparation (windows7+mysql-8.0.18...

How to use xshell to connect to Linux in VMware (2 methods)

【Foreword】 Recently I want to stress test ITOO...

How to start the spring-boot project using the built-in linux system in win10

1. Install the built-in Linux subsystem of win10 ...

Let’s talk about the symbol data type in ES6 in detail

Table of contents Symbol Data Type The reason why...

Win10 installation Linux system tutorial diagram

To install a virtual machine on a Windows system,...

About deploying a web project to Alibaba Cloud Server (5 steps to do it)

1. First log in to the Alibaba Cloud website to r...

A brief discussion on mobile terminal adaptation

Preface The writing of front-end code can never e...

Solution to the 404/503 problem when logging in to TeamCenter12

TeamCenter12 enters the account password and clic...

How to view and set the mysql time zone

1. Check the database time zone show variables li...

Hyper-V Introduction and Installation and Use (Detailed Illustrations)

Preface: As a giant in the IT industry, Microsoft...

Summary of commonly used SQL in MySQL operation tables

1. View the types of fields in the table describe...

Introduction to major browsers and their kernels

Trident core: IE, MaxThon, TT, The World, 360, So...