1. 程式人生 > >關於MySQL中自增的理解和設定

關於MySQL中自增的理解和設定

show create table t10;--查看錶的建立結果
show create table t10\G;--豎列檢視
alter table t10 AUTO_INCREMENT =20 --設定自增為20
alter table t2.name  char(30);
insert into t2(name) values ('yaoming');
ALTER TABLE t2 ALTER Column Name varchar(100) not null;
主鍵:
    1.一個表只能有一個主鍵,主鍵可以由多列組成,主鍵不能為空.
    CREATE TABLE t5 (
                    nid 
int(11) NOT NULL AUTO_INCREMENT, pid int(11) not NULL, num int(11), primary key(nid,pid) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 外來鍵: 1.建立外來鍵時可以在一個表示式中建立多個外來鍵 create table t5( id int auto_increment primary key, name
char(10), nid int, pid int, )engine = innodb default charset=utf8; create table t6( id int auto_increment primary key, name char(10), id1 int, id2 int, constraint fk_t5_t6 foreign key (id1,id2) references t1(nid,pid) )engine = innodb default
charset=utf8; 資料行: 插入多個數據是可以在values後面使用,分割寫 insert into tb1(name,age) values ('xiaoli',18),('xiaoming',12) 自增: show create table t2\G 可以檢視建立表時的結構 alter create table t2 auto_increment = 20; --可以改變自增的起始數字 MySQL:自增步長: --基於會話級別的: show session variables like 'auto_inc%';--檢視全域性變數的步長和起始值 set session auto_increment_increment=2; --設定步長 set session auto_increment_offset=10; --設定起始數字 --基於全域性級別的: show global variables like 'auto_inc%'; --檢視全域性變數 set global auto_increment_increment=2; --設定全域性步長 set global auto_increment_offset=10; --設定全域性起始數字 SqlServer: 自增步長基於表可以實現 create table t2( sid int primary key identity(3,5),--從3開始 ,步長為5 sname nchar(8) not null, ssex nchar(1) )