MySQL數(shù)據(jù)庫之?dāng)?shù)據(jù)data?基本操作
更新時間:2022年05月04日 13:20:58 作者:彭世瑜psy
這篇文章主要介紹了MySQL數(shù)據(jù)庫之?dāng)?shù)據(jù)data?基本操作,文章基于MySQL的相關(guān)資料展開數(shù)據(jù)data?基本操作,具有一定的參考價值,需要的小伙伴可以參考一下
插入操作
-- 方式一:插入指定字段數(shù)據(jù)(推薦使用) insert into 表名 [(字段列表)] values (對應(yīng)列數(shù)據(jù)); -- 方式二:插入所有字段對應(yīng)的數(shù)據(jù) insert into 表名 values (對應(yīng)列數(shù)據(jù));
示例:
create table tb_teacher( name varchar(10), age int ); -- 插入一條數(shù)據(jù) insert into tb_teacher (name, age) values ('Jack', 24); -- 字段名和值需要一一對應(yīng) insert into tb_teacher (age, name) values (25, 'Tom'); -- 可以只插入部分字段數(shù)據(jù) insert into tb_teacher (name) values ('Steve'); -- 插入全部字段對應(yīng)的數(shù)據(jù),此時值列表需要對應(yīng)表結(jié)構(gòu) insert into tb_teacher values ('Jery', 23);
查詢操作
-- 查詢表中全部字段數(shù)據(jù) select * from 表名; -- 查詢表中部分字段數(shù)據(jù) select 字段列表 from 表名; -- 簡單條件查詢數(shù)據(jù) select 字段列表/* from 表名 where 字段名 = 值;
示例:
-- 查詢所有數(shù)據(jù) select * from tb_teacher; +-------+------+ | name | age | +-------+------+ | Jack | 24 | | Tom | 25 | | Steve | NULL | | Jery | 23 | +-------+------+ -- 指定字段 select name from tb_teacher; +-------+ | name | +-------+ | Jack | | Tom | | Steve | | Jery | +-------+ -- 限制條件, 年齡==23 select name from tb_teacher where age = 23; +------+ | name | +------+ | Jery | +------+
刪除操作
-- 如果沒有條件,會刪除所有數(shù)據(jù) delete from 表名 [where 條件];
-- 刪除年齡為23的數(shù)據(jù) delete from tb_teacher where age = 23; select * from tb_teacher; +-------+------+ | name | age | +-------+------+ | Jack | 24 | | Tom | 25 | | Steve | NULL | +-------+------+
更新操作
-- 如果沒有where條件,將會更新表中所有的值 update 表名 set 字段名 = 新值 [where 條件];
示例:
-- 更新Tom的年齡為26 update tb_teacher set age = 26 where name = 'Tom'; select * from tb_teacher; +-------+------+ | name | age | +-------+------+ | Jack | 24 | | Tom | 26 | | Steve | NULL | +-------+------+
到此這篇關(guān)于MySQL數(shù)據(jù)庫之?dāng)?shù)據(jù)data 基本操作的文章就介紹到這了,更多相關(guān)MySQL data內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Canal進(jìn)行MySQL到MySQL數(shù)據(jù)庫全量+增量同步踩坑指南
這篇文章主要介紹了使用Canal作為遷移工具,將數(shù)據(jù)庫從A服務(wù)器遷移至B服務(wù)器,為了盡量減少遷移導(dǎo)致的停機(jī)時間,考慮使用全量遷移+增量同步的方式2023-10-10MySQL中json_extract()函數(shù)的使用實例
這篇文章主要介紹了MySQL中json_extract()函數(shù)的使用實例,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-07-07