-- 新增age字段在第一行
alter table student add column age int first;
alter table banji add column class int after id;
-- 新增age字段在name字段后面一行
alter table student add ages int after name;
alter table student add class int after gender;
-- 修改number字段属性为varchar(20)
alter table my_primaly1 modify number varchar(20);
-- 修改number字段为char(10),放在id后面一行
alter table student modify number char(10) after id;
-- 把id字段放在第一行
alter table student modify id int first;
-- 重命名student表的age字段为sex char(10)
alter table student change ages sex char(10);
-- 重命名主键时不用加primary key auto_increment,否则提示multiple primary key are defined.
alter table banji change banji id class int;
-- 新增student表的数据
insert into student values(2,28,54,'xiaowang',1,'male'),(3,22,86,'xiaohua',2,'female'),(4,24,45,'xiaowang',2,'female');
-- 新增student表的部分字段数据
insert into student(number,gender,name,id,age) values('wanyi001','male','tom',5,32),('wanyi002','male','lili',6,33);
-- 修改student表的name=xiaoming的行的gender字段值为female
update student set gender='female' where name='xiaoming';
update banji set name='制药工程' where id=1 ;
update banji set name='药剂学' where id=2 ;
-- 3-08修改表选项的自增起始值(默认为1),向下无效,向上有效
alter table my_primaly1 auto_increment =10;
-- 把名字叫李娜的前2个人的学号改为200908020019
update myprimary set number =200908020019 where name='李娜' limit 2;
-- 把id字段放到第一行
alter table student change id id int first;
-- 删除-- 删除-- 删除-- 删除-- 删除-- 删除-- 删除-- 删除-- 删除-- 删除-- 删除-- 删除-- 删除-- 删除-- 删除-- 删除
-- 删除数据库
drop database mydatabase;
-- 删除表
drop table my_class;
-- 删除所有sex字段不为空的数据
delete from student where sex;
-- 删除id>2的所有数据
delete from banji where id>2;
-- 删除字段sex
alter table student drop column sex;
-- 删空了自增长还是原来的
delete from my_class;
-- 清空表数据,重置自增长
truncate my_class;
-- 删除主键
alter table my_primaly modify1 id int;
-- 下面为错误
alter table my_primaly modify1 id int primaly key;
-- mysql的记录长度对大为65535个字节
-- 释放null,把65535字节用完,不写null就是默认为null-- 就是可以为空
-- 1+ 21844*3+2=65535
create table myutf81(age tinyint not null,name varchar(21844) not null)charset utf8;
-- 1+ 32766*2+2=65535
create table mygbk1(age tinyint not null,name varchar(32766) not null)charset gbk;
-- 证明text字段占用10个字节长度
-- 10+ 21841*3 +2=65535
create table myutf8text1(textf text not null,name varchar(21841) not null default 0)charset utf8;
-- 10+ 32761*2 +1 +2=65535
create table mygbktext1(textf text not null comment '文本字段',age tinyint not null comment '迷你整型',name varchar(32761) not null comment '变长字符串')charset gbk;
-- 3-02增加主键
create table my_primaly1(id int primary key auto_increment comment '逻辑主见:自增长',name varchar(20)not null comment '姓名',number char(10) not null comment '学号')charset utf8;
-- 修改number
alter table my_primaly1 modify number varchar(20);
insert into my_primaly1(name) values('邓丽君');
insert into my_primaly1 values(null,'长孙玄奇',200902020012);
insert into my_primaly1 values(default,欧阳修',200908020018);
insert into my_primaly1 values(1,'圣',200908020013);
insert into my_primaly1 values(2,'宋',200908020012);
insert into my_primaly1 values(3,'彭',200908020011);
insert into my_primaly1 values(4,'刘',200908020014);