mysql 自增列的建立

2021-05-22 09:01:14 字數 411 閱讀 3043

1.建表時就建立自增列:

create table test

(id int auto_increment primary key,

name varchar(20) not null,

password varchar(20) not null

);insert

into

test values(null,'aa','aa');

insert

into

test values(null,'bb','bb');

注意:插入語句時,自增列的值為null。

2、建立**後新增: alter table table1 add id int auto_increment primary key 自增字段,一定要設定為primary key.

orcle建立自增列

剛剛用orcle,組長讓我設計一張表,結果設計完了以後就在plsql設計主鍵id,因為如果不用自增列的話就得用復合主鍵,所以就想著用id的自增列來表示。可是他和sql server又有點不太一樣,他沒又自增列。所以在網上查了一下,兩種方法。首先先建立一張測試表t demo create table ...

Mysql 自增列 主鍵

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

oracle 自增列建立方法

oracle沒有oracle自增字段這樣的功能,但是通過觸發器 trigger 和序列 sequence 可以實現。先建乙個測試表了 create table userlogin id number 6 not null,name varchar2 30 not null primary key t...