资讯详情

mysql的增删改查

增:

改:

删:

查:

这是一个更全面的数据库操作


id name
99 您好

增:

//前是id后是values insert into table(key,key) values (values,values)  ///数字不需要加单引号,字符需要加单引号 insert into table(id,name) values(99,你好)
id name
99 您好
将key name为您好的id改为88 88 您好
将所有id改为77 77 您好
在id原基础上加22 99 您好

//将name为您好的id改为88 update table set id=88 where name='您好'  //将   所有的id  都改为77 update table set id=77  //在原基础上id加22 update table set id=id 22 where name='您好';  

【删表,这个表不存在】 id name
99 您好
将key name为您好的id改为88 88 您好
将所有id改为77 【删除表中id为77的数据】 null null
在id原基础上加22 99 您好

删:

///删除表中id为77的数据 delete form table where id=77  ///删表操作 delete form table

查:

///查询所有数据 select * form table  //根据key查值 将表中的id和name字段查出来 select id,name form table  ///搜索前十条数据 select * form  table limit 10;  //从第五条开始取10条数据 select *  from table limit 5,10;   //查询id为77的name select name form table where id='77'  //查询id100-66中间的数据 select * form table where id<=100 and id=>66

mysql它是一个关系数据库。数据库默认为升序,因此有表和表之间的链接。这种情况是左连接 右连接 内连接。

左连接以左表为标准,右表为标准null

右连接以左表为标准,左表为标准null

内部连接叉连接

这是一个更全面的数据库操作

select * from sc select * from student select * from course  --插入新生李一和李二 insert into student(sno,sname,sex,dno,BIRTHDAY)  values李一,‘男’,‘001’,‘1985-01-02’ select * from student  where sname = '李一' insert into student(sno,sname,sex,dno,BIRTHDAY)  values李二,女,'1986-01-02') select * from student  where sname = '李二'  --创建新表 CREATE TABLE chengjiao (  SNO char (8) not null unique,  SNAME char(10),  SEX char(2),  DNO char(8),  AGE smallint,  BIRTHDAY datetime )   --插入新生张三、王二、张三 INSERT INTO student(SNO,SNAME,AGE,DNO)   VALUES 张三,20,'0002')  INSERT INTO chengjiao(SNO,SNAME,AGE,DNO) VALUES (20067011,王二,23,0003 INSERT INTO chengjiao(SNO,SNAME,AGE,DNO) VALUES 张三,19,'0003')  select * from student  where sno = '20067027' union select * from student  where sno = '20067011' union select * from student  where sno = '20067021'  --将教表 chengjiao 中的所有学生一次性添加到学生表 student 中。
insert into student(sno,sname,sex,dno,age,birthday)
(select sno,sname,sex,dno,age,birthday from chengjiao)
select * from chengjiao

--依据学生的生日,计算出该学生的年龄
update student
set age = (year(getdate()) - year(birthday))

--将所有安排在 A209 的课程调整到 D109 
update course
set room = 'D109'
where room = 'A209'

--将选课表中的‘线性代数’课程的成绩减去 4 分
update sc
set grade = grade-4
where cno in (select cno from course
				where cname = '线性代数')
				
--从排课表中删除‘杨丽’老师的所有排课纪录
delete from course
where tname = '杨丽'

--删除学院编号为空的学生记录及选课记录,判断空不要使用=null,因为出来的结果未必只有一个,=只适用于一个值的情况
delete from sc
where sno in (select sno from student 
				where dno is null)
				
--删除表 ’excelxuanke’
drop table excelxuanke

--(1)在选课表中插入一个新的选课记录,学号为 20002059,授课班号为 244501,成绩 80分。
insert into sc(sno,cno,grade)
values('20002059','244501',80)

--(2)从选课表中删除选修‘线性代数’的选修纪录
delete from sc
where cno in (select cno from course where cname = '线性代数')

--(3)将机电学院的女生一次性添加到成教表中
insert into chengjiao(sno,sname,sex,dno,age,birthday)
(select sno,sname,sex,dno,age,birthday from student where dno='0001')

--(4)将所有学生的高等数学成绩加5分
update sc
set grade = grade + 5
where cno in (select cno from course where cname = '高等数学')

--(5)将学号尾数为‘4’的同学成绩加 2
update sc
set grade = grade + 2
where sno like '%4'

--(6)删除电科系所有学生的选课记录
delete from sc
where sno in (select * from student where dno = '0001')

--(7)将学号为“20002059”的学生姓名改为“王菲”
update student
set sname = '王菲'
where sno = '20002059'

--(8)删除成绩为空的选课记录
delete from sc
where grade is null

标签: le36sn08dno传感器

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

锐单商城 - 一站式电子元器件采购平台