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) )