MySQL標識列(自增列設定,修改,刪除)

2021-09-29 08:06:32 字數 632 閱讀 7610

標識列:又稱之為自增長列

含義:可以不用手動的插入值,系統提供預設的序列值。(預設從1開始,每次自增1)

(1)建立表時設定標識列:

id int primary key auto-increment;
(自增列插入值時可以把對應的列寫null,系統預設給值)

例如:

insert table student values(null,'張三');
(2)修改表時設定標識列:

alter table student modify column id int primary key auto-increment;
註解:

1. modify column 表示修改型別。

2. auto-increment 表示自增。

(3)刪除自增列:

alter table student modify column in int;
標識列的特點:

標識列不一定和主鍵搭配,也可以是unique(唯一),外來鍵等。

乙個表中最多只能有乙個標識列。

標識列的型別只能是數值型(int,float,double)。

mysql標識列 自增長列

直接po 和案例 標識列 又稱為自增長列 含義 可以不用手動的插入值,系統提供預設的序列值 特點 1 標識列必須和主鍵搭配嗎?不一定,但要求是乙個key 2 乙個表可以有幾個標識列?至多乙個!3 標識列的型別只能是數值型 4 標識列可以通過 set auto increment increment ...

mysql 標識列 自增長列

1.含義 可以不用手動插入值,系統提供預設的序列值 2.特點 1 標識列不一定必須和主鍵搭配,但要求是乙個key 主鍵 unique 外來鍵 2 乙個表最多有乙個標識列 3 標識列的型別只能是數值型 int float double等 4 標識列可以通過 set auto increment inc...

Mysql 自增列 主鍵

mysql中假如有 id int auto increment,cid varchar 36 通常情況下都是 id設定為主鍵。假如要設定cid為主鍵。自增列id必需是唯一索引。create table temp id bigint not null auto increment comment 編號...