數(shù)據(jù)操作DML
這里的數(shù)據(jù)操作就是增刪改的更新操作,不包括查詢
插入
insert into 表 (列名1,列名2,列名3...) values (值1,值2,值3...); //向表中插入對(duì)應(yīng)列
insert into 表 values (值1,值2,值3...); //向表中插入所有列
第一種是需要按照列名對(duì)應(yīng)寫數(shù)值的,可以省略,但必須對(duì)應(yīng)
第二種是一次插入一行,是都要寫的
也可以插入多行只需在之后填入新的行即可
insert into student(sid,name,gender,age,birth,address,score)
values(1001,'男',18,'1996-12-23','北京',83.5),
(1001,'男',18,'1996-12-23','北京',83.5);
insert into student values(1001,'男',18,'1996-12-23','北京',83.5);
修改
update 表名 set 字段名=值,字段名=值...;
update 表名 set 字段名=值,字段名=值... where 條件;
例如
-- 將所有學(xué)生的地址修改為重慶
update student set address = '重慶';
-- 講id為1004的學(xué)生的地址修改為北京
update student set address = '北京' where id = 1004
-- 講id為1005的學(xué)生的地址修改為北京,成績(jī)修成績(jī)修改為100
update student set address = '廣州',score=100 where id = 1005
刪除
delete from 表名 [where 條件];
truncate table 表名;
truncate 表名;
例如文章來源:http://www.zghlxwxcb.cn/news/detail-823460.html
-- 1.刪除sid為1004的學(xué)生數(shù)據(jù)
delete from student where sid = 1004;
-- 2.刪除表所有數(shù)據(jù)
delete from student;
-- 3.清空表數(shù)據(jù)
truncate table student;
truncate student;
需要注意的是delete和truncate原理不同,delete只刪除內(nèi)容,而truncate類似于drop table ,可以理解為是將整個(gè)表刪除,然后再創(chuàng)建該表。之后再學(xué)習(xí)其他內(nèi)容的時(shí)候我們會(huì)繼續(xù)補(bǔ)充其中的內(nèi)容。文章來源地址http://www.zghlxwxcb.cn/news/detail-823460.html
到了這里,關(guān)于MySQL之?dāng)?shù)據(jù)庫DML的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!