MySQL 数据操作
发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,-- 插入信息-- 方法1:insert...values-- 单条语句insert into 表名 values (数据);eg:insert into class values (21403001
千家信息网最后更新 2026年11月02日MySQL 数据操作-- 插入信息
-- 方法1:insert...values
-- 单条语句
insert into 表名 values (数据);
eg:
insert into class values (21403001,'张三','男',20,'重庆');
-- 多条语句
insert into 表名 values (数据),(数据),(数据);
eg:
insert into class values
(null,'小花1','女',31,'河北3',null,null),
(null,'小花1','女',31,'河北3',null,null),
(null,'小花1','女',31,'河北3',null,null);
-- 方法2:insert...set
insert into 表名 set 字段1=值1,字段2=值2,...字段n=值n;
eg:
insert into class set id=null,name='小花1',sex='女',age=32,address='河北3',birthday=null,remark=null;
-- 方法3:insert...select
insert into 插入的表 select * from 原表;
eg:
insert into class1 select * from class;
-- 查询数据
-- 方法1:查询特定的行与列
select 字段 from 表名 where 条件表达式;
eg:
select id, name from class where id<=21403005 and name<>'王五';
--备注:查询 字段 id<=21403005,但不包含 字段 name='王五' 的数据;
-- 方法2:限制结果集
select * from 表名 limit 条数;
eg:
select * from class limit 7;
-- 备注:数字是多少,就显示多少条数据
-- 方法3:排序结果集
select * from 表名 order by 字段 asc;
eg:
select * from class order by name asc;
-- 备注:如果 字段 是数字,则按大小排序;如果是汉字或字母,则按字母排序;
-- 更新(修改)数据
update 表名 set 字段名=值,字段名=值,字段名=值,..... where 条件表达式;
eg:
update class set name = '张三',age='50' where id = 21403012;
--备注: 修改 学号 为 21403012 的 姓名 和 年龄
-- 删除数据
-- 方法1:如果不使用 where,则会删除所有数据
delete from 表名 where [字段=值];
delete from 表名 where 条件表达式;
-- 提交事务后生效,truncate不能保证事务的安全性。
eg:
delete from class2 where address="上海"; -- 指定字段 删除 数据
-- 查看表
select * from 表名;
eg:
select * from class2;
-- 查看所有表
show tables;
-- 查看 表结构
describe 表名;
eg:
describe class;
-- 方法1:insert...values
-- 单条语句
insert into 表名 values (数据);
eg:
insert into class values (21403001,'张三','男',20,'重庆');
-- 多条语句
insert into 表名 values (数据),(数据),(数据);
eg:
insert into class values
(null,'小花1','女',31,'河北3',null,null),
(null,'小花1','女',31,'河北3',null,null),
(null,'小花1','女',31,'河北3',null,null);
-- 方法2:insert...set
insert into 表名 set 字段1=值1,字段2=值2,...字段n=值n;
eg:
insert into class set id=null,name='小花1',sex='女',age=32,address='河北3',birthday=null,remark=null;
-- 方法3:insert...select
insert into 插入的表 select * from 原表;
eg:
insert into class1 select * from class;
-- 查询数据
-- 方法1:查询特定的行与列
select 字段 from 表名 where 条件表达式;
eg:
select id, name from class where id<=21403005 and name<>'王五';
--备注:查询 字段 id<=21403005,但不包含 字段 name='王五' 的数据;
-- 方法2:限制结果集
select * from 表名 limit 条数;
eg:
select * from class limit 7;
-- 备注:数字是多少,就显示多少条数据
-- 方法3:排序结果集
select * from 表名 order by 字段 asc;
eg:
select * from class order by name asc;
-- 备注:如果 字段 是数字,则按大小排序;如果是汉字或字母,则按字母排序;
-- 更新(修改)数据
update 表名 set 字段名=值,字段名=值,字段名=值,..... where 条件表达式;
eg:
update class set name = '张三',age='50' where id = 21403012;
--备注: 修改 学号 为 21403012 的 姓名 和 年龄
-- 删除数据
-- 方法1:如果不使用 where,则会删除所有数据
delete from 表名 where [字段=值];
delete from 表名 where 条件表达式;
-- 提交事务后生效,truncate不能保证事务的安全性。
eg:
delete from class2 where address="上海"; -- 指定字段 删除 数据
-- 查看表
select * from 表名;
eg:
select * from class2;
-- 查看所有表
show tables;
-- 查看 表结构
describe 表名;
eg:
describe class;
字段
数据
方法
备注
小花
河北
条件
表达式
排序
查询
事务
字母
数字
结果
语句
张三
王五
安全
信息
多条
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
互联网科技有限公司
互联网电商科技
金融科技与互联网金融
美国互联网科技
互联网科技论文
智慧科技互联网
成都狮子座互联网科技
崇明区互联网教育科技诚信经营
迪庆互联网科技招生
世界互联网领先科技成果获奖
上海创道互联网络科技有限公司
从那以后互联网科技有限公司
济南小医互联网科技有限公司招聘
互联网科技新闻
互联网科技和医药行业
互联网科技大会大佬
长沙易易互联网科技有限公司
互联网领先科技成果宣传视频
上海互联网科技园景观
瑞安市蟠桃会互联网科技有限公司
为想互联网科技
紫鲸互联网科技
上海喔噻互联网科技
上海致骋互联网科技
科技互联网海报
上海钢联属于互联网科技股吗
启辰互联网科技
悟空问答互联网科技
上海旺乐尼互联网科技有限公司
宁波允成互联网科技有限公司