【Mysql】之基础sql语句模板
==============新建数据库============ create database if not exists XXX; ==============删除数据库============ drop database if exists XXX; ==============新建表================ create table if not exists z_class( z_id int UNSIGNED auto_increment, z_name VARCHAR(100) NOT NULL, z_age INT NOT NULL, z_date date, PRIMARY KEY(z_id) )ENGINE=INNODB DEFAULT charset=utf8; ==============插入数据============= insert into XXX(,,,)values (,,,), (,,,), (,,,); ==============复制数据============= create table XXX2 like XXX1; 复制表结构 insert into XXX2 select * from XXX1; 复制数据 ==============删除数据============= delete from XXX where id=y; ============删除全部数据=========== delete from XXX; ============排序删除数据=========== delete from XXX order by xxx limit 2; ==============更新数据============= update XXX set xxx = y where id = z; ============多表更新数据=========== update XXX1 set x01 =( select y01 from XXX2 where y02 = 'y' order by rand() limit 1 ) where x02 is null; ===========修改表结构属性========== alter table XXX1 change column xxx xxx int(10) not null; ===========添加表结构属性========== alter table XXX1 add column info varchar(10) null after xxx01; ===========删除表结构属性========== alter table XXX1 drop column xxx01; ===========修改表名称属性========== alter table XXX1 rename to XXX2; 或者 rename table XXX1 to XXX2; ==============查询数据============= select * from XXX1 where xxx01 <= 3; 模糊查询: select * from XXX1 where xxx01 like '%o' 排序: select * from XXX1 order by xxx01 select * from XXX1 order by xxx01 desc 聚合: select sum(xxx01),xxx02 from XXX1 group by xxx02 平均值: select avg(xxx01) from XXX1 合计: select sum(xxx01) from XXX1 最大: select max(xxx01) from XXX1 最小: select min(xxx01) from XXX1 合计总行数: select count(xxx01) from XXX1 分组查询sal字段的最大值:id,sal,num select max(sal),num from XXX1 group by num 查询之间的数: select * from XXX1 where between 1 and 3 查询指定行的数据: select * from XXX1 limit 3,2 不包含第三行,向下查询2行(4,5行) 查询表结构: desc XXX1 创建视图: create view st as select * from XXX1 where xxx01 = 'x' 删除视图: drop view st
不积跬步,无以致千里;不集小流,无以成江海。
如转载本文,请还多关注一下我的博客:https://www.cnblogs.com/Owen-ET/;
我的Github地址:https://github.com/Owen-ET————————————
无善无恶心之体, 有善有恶意之动, 知善知恶是良知, 为善去恶是格物。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App