課程總結(jié)
? ? 表中列的 增刪改查
表是由 列和行 組成的珠十;對(duì)列的增刪改查就相當(dāng)于是對(duì)表屬性的修改? ? 所以用alter
列屬性
6. 列的屬性和約束
6.1 主鍵: primary key (PK)
說明:
唯一
非空
數(shù)字列,整數(shù)列凭豪,無關(guān)列焙蹭,自增的.
是一種約束,也是一種索引類型嫂伞,在一張表中只能有一個(gè)主鍵孔厉。
6.2 非空: Not NULL
說明:
我們建議,對(duì)于普通列來講帖努,盡量設(shè)置not null
默認(rèn)值 default : 數(shù)字列的默認(rèn)值使用0 ,字符串類型撰豺,設(shè)置為一個(gè)nil null
6.3 唯一:unique
不能重復(fù)
6.4 自增 auto_increment
針對(duì)數(shù)字列,自動(dòng)生成順序值
6.5 無符號(hào) unsigned
針對(duì)數(shù)字列?
6.6 注釋 comment
增列
增列=改表結(jié)構(gòu)屬性 所以用alter
添加列
alter? table oldguo add telnum char(11) not null unique comment '手機(jī)號(hào)';
alter? table oldguo add state tinyint unsigend not null default 1 comment '狀態(tài)信息';
指定位置? 添加列
alter? table oldguo add 列名 varchar(255) not null unique comment 'qq號(hào)碼' after name;
在name后邊添加qq列varchar(255): after name
alter table oldguo add 列名 varchar(255) not null unique comment '學(xué)生號(hào)' first;
在首列上添加學(xué)號(hào)列 sid拼余;? ? first
創(chuàng)建一個(gè)相同表結(jié)構(gòu)的空表:
create table oguo like oldguo;
查看列屬性
desc 表名;
查看表屬性=查看列屬性
改列屬性
alter table oldguo change gender gg char(1) not null default 'n';
將gender改為gg? 數(shù)據(jù)類型改為char(1)數(shù)據(jù)類型
alter table oldguo modify name varchar(128) not null;
修改已有列name的屬性
刪除列
alter table oldguo drop? state;