MySQL增删改查功能的操作
admin
2023-04-20 11:04:23
0

本文主要给大家简单讲讲MySQL增删改查功能的操作,相关专业术语大家可以上网查查或者找一些相关书籍补充一下,这里就不涉猎了,我们就直奔主题吧,希望MySQL增删改查功能的操作这篇文章可以给大家带来一些实际帮助。

一、操作表记录(增删改查,Create,Read,Update,Delete)

1.Insert

INSERT INTO table_name [(column [,column.....])] VALUES (value [,value......]);

INSERT INTO employee (id,name,gender,birthday,entry_data,job,salay,resume)
VALUES (null,'赖泽铵','男','1996-7-7','2018-12-8','python工程师',5000,'啥都会');

insert into employee values (null,'吴志雄','男','2000-1-1','2001-2-2','董事长','1','全靠他了'),(null,'赖泽铵','男','1996-7-7','2018-12-8','python工程师',5000,'啥都会');  #所有列都写入可以不写 ,插入多条

2.Update

UPDATE tbl_name SET col_name=exprl [,col_name2=expr2......]
(1)将所有员工薪水改为5000

update employee set salay= 5000;

(2)将赖泽铵薪水改为3000

update employee set salay = 3000 where name='赖泽铵';

(3)将侯文泽薪水改为4000,job改为c++

update employee set salay = 4000,job = 'c++' where name = '侯文泽';

(4)将郑嘉颖薪水增加1000

update employee set salay = salay+1000 where name = '郑嘉颖';

3.Delet (truncate)  #truncate整表摧毁

delete from table_name [WHERE where_definition]

(1)删除表中名为侯文泽的记录

delete from employee where name = '侯文泽';

(2)删除表中所有记录

delete from employee;

(3)使用truncate删除表中记录

truncate employee;

4.Select

SELECT [DISTINCT] * | {column1,column2,......} FROM table;

(1)查询表中所有员工的信息

select * from employee;

(2)查询表中所有员工的姓名和薪水

select name,salay from employee;

(3)过滤表中重复数据

select distinct salay from employee;

(4)在所有员工薪水上+1000

select name,salay+1000 from employee;

(5)统计每个学生的总分

create table grade (
id INT primary key AUTO_INCREMENT,
name varchar(20),
chinese INT,
math INT,
english INT
);

insert into grade values (null,'侯文泽',70,80,90),(null,'郑嘉颖',79,85,92),(null,'赖泽铵',90,90,40);

select name,chinese+math+english from grade;

(6)使用别名表示学生的总分

select name as 姓名 ,chinese+math+english as 总成绩 from grade;

select name  姓名 ,chinese+math+english  总成绩 from grade;

5.带有where的查询

(1)查询姓名为xxx的学生成绩

select * from grade where name = '赖泽铵';

(2)查询英语成绩大于90的同学

select * from grade where english>90;

(3)查询总分大于230分的所有同学

select * from grade where chinese+math+english>230;

(4)where 常用运算符

~:>  <  <=  >=  =  <>#不等于

select * from grade where chinese<>80;

~:between ...  and ....  #在之间

select * from grade where math between 70 and 85;

~:in(set)                    #括号内为集合

select * from grade where english in (80,85,90);

~:like                        #像,通配符% ,‘_’   表示一个字符

select * from grade where name like '赖%';

select * from grade where name like '文';

~:and or not          #逻辑运算符

MySQL增删改查功能的操作就先给大家讲到这里,对于其它相关问题大家想要了解的可以持续关注我们的行业资讯。我们的板块内容每天都会捕捉一些行业新闻及专业知识分享给大家的。

相关内容

热门资讯

燃气发电与电池储能相结合,成为... 来源:市场资讯 (来源:i商周) 孟菲斯一座xAI数据中心的燃气轮机 人工智能的用电飙升,让数据中心...
景嘉微:JM11性能大幅提升,... 有投资者在互动平台向景嘉微提问:“董秘您好!关注到近期有用户反馈公司JM11显卡推出了适配windo...
原创 v... 影像的发展进一步推动,不少品牌推出了专业影像手机,拥有2亿像素摄像头、色彩还原摄像头、影像芯片、影像...
荣耀首款自研耳夹式耳机官宣即将... 快科技5月13日消息,日前,荣耀首席营销官关海涛宣布,荣耀全场景团队自研首款耳夹式耳机马上上市,并称...
谷歌推出Googlebooks... IT之家 5 月 13 日消息,2026 年 I/O 开发者大会下周(5 月 19~20 日)召开之...
自控所推动GNC专业智能化升级 来源:滚动播报 (来源:中国航空报) 本报讯 5月6日,航空工业自控所召开 GNC+AI关键技术研发...
华电电力申请数据库访问方法专利... 国家知识产权局信息显示,华电电力科学研究院有限公司申请一项名为“数据库访问方法、装置、设备及介质”的...
苏州率先打造数据流通利用新范式 数据,作为第五大生产要素 具有流动性强、非消耗性、非均质性等特点 苏州率先打造数据流通利用新范式 夯...
伊媒披露伊美新一轮谈判5个先决... 当地时间5月12日,据伊朗法尔斯通讯社援引知情人士消息报道,伊朗对与美国新一轮谈判提出的5个先决条件...
英国将向霍尔木兹海峡多国护航行... 当地时间12日,总台记者从英国国防部获悉,英国将向在霍尔木兹海峡执行任务的多国护航行动提供无人机、战...