007.2.1修改表结构 MySQL (1)增加字段(新列 语法格式: alter table表名 ad新字段名数据类型[约束条件][ first after 已存在字段名]; MySQL数据库应用》http:/mysq!xg.hactcm.edu.cn 第6页
《MySQL数据库应用》 http://mysql.xg.hactcm.edu.cn/ 第 6 页 7. 2.1 修改表结构 (1)增加字段(新列) 语法格式: alter table 表名 add 新字段名 数据类型 [约束条件] [first I after 已存在字段名];
007.2.1修改表结构 MySQL 案例1:在ⅹscj数据库的xs表中,增加“奖学金等级”列。 alter table xs add奖学金等级 tiny int; 案例2:在数据表dept1中添加一个nt类型的字段 column2,并设 置为该表的第一个字段。 alter tab le dept1 add column2 int first; MySQL数据库应用》http:/mysq!xg.hactcm.edu.cn 第7页
《MySQL数据库应用》 http://mysql.xg.hactcm.edu.cn/ 第 7 页 7. 2.1 修改表结构 案例1:在xscj数据库的xs表中,增加“奖学金等级”列。 alter table xs add 奖学金等级 tinyint; 案例2:在数据表dept1中添加一个int类型的字段column2,并设 置为该表的第一个字段。 alter table dept1 add column2 int first;
007.2.1修改表结构 MySQL 案例3:在数据表dept1中name列后添加一个int类型的字段 co|umn3。 alter tab le dept1 add co l umn3 int after name 案例4:在数据表dept1中添加一个不能为空的 varchar(12类 型的字段 column1。 alter table dept1 add co l umn varchar(12)not nul I MySQL数据库应用》http:/mysq!xg.hactcm.edu.cn 第8页
《MySQL数据库应用》 http://mysql.xg.hactcm.edu.cn/ 第 8 页 7. 2.1 修改表结构 案例3:在数据表dept1中name列后添加一个int类型的字段 column3。 alter table dept1 add column3 int after name; 案例4:在数据表dept1中添加一个不能为空的varchar(12)类 型的字段column1。 alter table dept1 add column1 varchar(12) not null;
MySQL ●000 案例5:在数据表dept1中添加三个int类型的字段 column4、 column5、co|umn6。 alter table dept 1 add col umn 4 int. add co lumn5 int. add co lumng int MySQL数据库应用》http:/mysq!xg.hactcm.edu.cn 第9页
《MySQL数据库应用》 http://mysql.xg.hactcm.edu.cn/ 第 9 页 案例5:在数据表dept1中添加三个int类型的字段column4、 column5、column6。 alter table dept1 add column4 int,add column5 int,add column6 int;
007.2.1修改表结构 MySQL (2)修改字段的数据类型 语法格式: alter table表名 modify字段名数据类型; 案例1:将数据表 uster的班级号列的数据类型改为 bigint; alter table uster modify班级号 bigint 案例2:将数据表dept1中name字段的数据类型修改为 varchar(8) alter table detp1 modify name varchar( 8) MySQL数据库应用》http:/mysq!xg.hactcm.edu.cn 第10页
《MySQL数据库应用》 http://mysql.xg.hactcm.edu.cn/ 第 10 页 7. 2.1 修改表结构 (2)修改字段的数据类型 语法格式: alter table 表名 modify 字段名 数据类型; 案例1:将数据表uster的班级号列的数据类型改为bigint; alter table uster modify 班级号 bigint ; 案例2: 将数据表dept1中name字段的数据类型修改为varchar(8) alter table detp1 modify name varchar(8) ;