5.修改表字段類型:
將name 的類型改為varchar(50);
alter table eurasis modify column name varchar(50);
6.修改字段名稱
將name 字段名稱修改為sex
alter table eurasis change column name sex varchar(20);
7.修改表名稱
alter table eurasis rename to student;
四.管理表數據
1.增加數據
插入所有字段
insert into student values(1,"mahuan",20);
插入部分字段
insert into student (id,age) values(2,22);
2.查詢數據
select * from student;
3.修改數據
全部修改
update student set age=44;
選擇性修改
update student set age=21,sex="xiaoming" where id=1;
4.刪除數據
delete from 和truncate table 的區別
delete from:
1.可以帶條件
2.只能刪除表的數據,不能刪除表的約束
3.刪除事物可以回滾(事物)
例如:有自增字段時,刪除后序列號會繼續接著上次增加
truncate table
1.不可帶條件
2.即能刪除表的數據,也能刪除表的約束
3.刪除事物不可以回滾(事物)
例如:有自增字段時,刪除后序列號會從1開始
不帶條件的刪除
delete from huan;
帶條件的刪除
delete from huan where name=huan;
小練習:
image.png
代碼實現:
create table employee( id int, name varchar(20), gender varchar(10),
birthday data, email varchar(10), remark varchar(50) );
alter table employee add column age int;
alter table employee modify column email varchar(50);
alter table employee drop column remark;
alter table employee change column name username varchar(20);
上接文章:Mysql學習筆記(1)-管理數據庫和管理表