数据库-----表的增删查改(数据库基础)

本文详细介绍SQL的基本操作,包括数据的增删改查。涵盖了单行和多行数据的插入、指定列查询、条件筛选、排序、去重、更新和删除等核心功能,适合初学者快速掌握SQL使用技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一.新增

1.单行数据全列插入

insert into 表名 values(数据1,数据2...);

2.多行数据+指定列插入

insert into 表名(指定列1,指定列2...) values(数据1,数据2);

二.查询

1.全列查询:

select * from 表名;

2.指定列查询:

select 指定列1,指定列2 from 表名;

3.查询字段为表达式:

select id,name,math + 10 from 表名;

4.别名:

select id,name 姓名,math + chinese 总分 from 表名;

5.去重:distinct

select distinct math from  表名;

6.排序:order by

desc------为降序
asc-------为升序(默认)
select name from student order by  qq_mail desc;

7.条件查询:where

1.基本查询
select name from student where math > 60;
2.andor
select name from student where math > 60 and chinese > 70;
3.范围查询
   1.between...and...
	select name from student where math between 60 and 70;  
   2.in
   select name from student where math in(60,70);
4.模糊查询:like
	--- % 匹配多个字符
	--- _ 匹配一个字符
select name from student where name like '张%';
5.NULL查询:
select name from student where qq_mail is NULL;

8.分页查询:

------从s到n页
select name from student where math > 60 limit n offset s;

三.修改:update

update 表名 set math = 80 where name = '张三';

四.删除:delete

delete from 表名 where name = '张三';
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值