Mysql學(xué)習(xí)筆記(2)-管理表數(shù)據(jù)

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;

四.管理表數(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開始

不帶條件的刪除

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ù)和管理表

文章文集:JavaEE--學(xué)習(xí)筆記

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容