5.修改表字段類(lèi)型:
將name 的類(lèi)型改為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;

四.管理表數(shù)據(jù)
1.增加數(shù)據(jù)
插入所有字段
insert into student values(1,"mahuan",20);
插入部分字段
insert into student (id,age) values(2,22);

2.查詢數(shù)據(jù)
select * from student;

3.修改數(shù)據(jù)
全部修改
update student set age=44;
選擇性修改

update student set age=21,sex="xiaoming" where id=1;

4.刪除數(shù)據(jù)
delete from 和truncate table 的區(qū)別
delete from:
1.可以帶條件
2.只能刪除表的數(shù)據(jù),不能刪除表的約束
3.刪除事物可以回滾(事物)
例如:有自增字段時(shí),刪除后序列號(hào)會(huì)繼續(xù)接著上次增加
truncate table
1.不可帶條件
2.即能刪除表的數(shù)據(jù),也能刪除表的約束
3.刪除事物不可以回滾(事物)
例如:有自增字段時(shí),刪除后序列號(hào)會(huì)從1開(kāi)始
不帶條件的刪除
delete from huan;
帶條件的刪除
delete from huan where name=huan;

小練習(xí):

image.png
代碼實(shí)現(xiàn):
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學(xué)習(xí)筆記(1)-管理數(shù)據(jù)庫(kù)和管理表