mysql自增的列,删除一些行后,为什么不是按顺序排列的?
如图所示,15到44之间删除了很多行,但45,46那些并没有被放到15与44之间,
而46到50之间删除的位置,却被后面的,52,51填充回去了,为什么会这样?而且是52在51之前?
然后,46到50之间应该有三个空位,但填充了两个之间,后面的53又跑到50后面去了,这又是为什么呢?
.................
看各位的回答,好像是我没有表达清楚。
我不是问15之后为什么不是16,而是问为什么44,46跑到52的前面去了??
回复内容:
如图所示,15到44之间删除了很多行,但45,46那些并没有被放到15与44之间,
而46到50之间删除的位置,却被后面的,52,51填充回去了,为什么会这样?而且是52在51之前?
然后,46到50之间应该有三个空位,但填充了两个之间,后面的53又跑到50后面去了,这又是为什么呢?
.................
看各位的回答,好像是我没有表达清楚。
我不是问15之后为什么不是16,而是问为什么44,46跑到52的前面去了??
自增和你删除数据没有必然联系吧,自增的ID有自己单独的序列,不是取表中的最大id+1
自增ID是会按照出现过的最大值增加的,不管你删没删。
MySQL会为每一个自增列储存一个这样的最大值,而不是每次都去表里查找最大的值。
效率问题,自己想……
另外,序号是有意义的,可参照数据库设计的基本原则。
每一个序号都对应着指定的一个事物。
这么设计也可以避免因为不完全的删除(比如另外一个表的列和ID相关,但是没有随之删除)而导致混乱。
最后……
我表示,多年经验,能不删的就不删。
完整性,可恢复性,数据挖掘……
加一个列作为标记(表明是否有效),比删除的设计要好。
PS:貌似发现自己没理解清问题……
排序的问题,看你的SQL啊,那么在意顺序的话,就写个order by咯。
如果需要按某个字段排序,需要 order by
要不然mysql只会按它的规则来显示数据,你没指定规则,就不要期待它符合你想要的规则
插入数据的时候就是排好序的么?
1.自增id是指在写表的时候自增长,而不是类似excel那样删除一行,下行自动上移。
2.顺序问题,你没执行sort?或者按别的字段sort了?

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

The page is blank after PHP connects to MySQL, and the reason why die() function fails. When learning the connection between PHP and MySQL database, you often encounter some confusing things...

CMS stands for Content Management System. It is a software application or platform that enables users to create, manage, and modify digital content without requiring advanced technical knowledge. CMS allows users to easily create and organize content
