1.create database; 数据库名 //创建一个数据库
2.show databases; //查看当前有哪些数据库
3.use 数据库名; //选择一个数据库进行操作
4.show tables; //查看当前有哪些表
5.desc 表名; //查看表结构
6.select * from 表名; //查看插入数据内容
7.drop table 表名; //删除表
8.drop database 数据库名 //删除数据库
9. create table 表名(名1 int,名2 varchar(20),名3 varchar(20),名4 int,名5 date)default charset=utf8;
10. insert into 表名(名1,名2,名3,名4,名5)values(1,"小米","男",99,now());
//update 修改
11, update 表名 set 字段名='新的内容' where id=1; //修改插入数据内容
@ alter table 表名 change 原名 新名 列类型; //修改列名
列:alter table a change d yyc varchar(20);
12. alter table 表名 add 子段名 类型 修饰 ; //修改数据表
// alter table yy add aa int(8); //添加列
13. alter table 表名 drop 列名称 //删除列
//alter table yy drop aa;
14. @ select * from yy where 名1=2; //单独查询其中一行信息 *:代表所有列
@ select fname,字段名1,字段名2 from 表; //查询其中一列的信息
@ select * from 表名 where 字段名 like "数值开头%"; //模糊查询
//聚合函数
@ select count(*) from 表名; //总数
//查询出当前表中的行数 count() 中也可以放字段
@ select max(id) from 表名; //最大值
//查询当前表中的id列最大的一个id
@ select min(id) from 表名; //最小值
//查询当前表中的id列最小的一个id
@ select avg(id) from 表名; //平均数
//查询当前表中的数据id总和的平均数
@ select sum(id) from 表名; //总合
//查询当前表中的数据id总合
@ 把id类型的数字排序
@ select 字段名id from 表名 order by 字段名id asc; //otder by 排序 ase:正排序
@ select 字段名id from 表名 order by 字段名id desc; //otder by 排序 desc:倒排序
]
15. delete from 表名 where 条件; //删除插入数据其中的一条内容
//delete from yy where 名1=2;
@ alter table m add primary key (a);//把原有的表添加主健
@ alter table qq modify a integer auto_increment; //把原有的表添加主健自增
@ alter table qq modify a int; //删除主健自增
@ alter table qq drop primary key; //删除主健
//添加主健自增首先要添加主健;
//删除主健首先要删除主健自增;
@alter table ff modify title varchar(20);//把非空变为空
16. //主见(名1)不被重复
方法一, create table www(名1 int primary key,名2 varchar(20),名3 varchar(20),名4 int,名5 date)default charset=utf8;
方法二, create table ww(名1 int,名2 varchar(20),名3 varchar(20),名4 int,名5 date,primary key(`名1`))default charset=utf8; (`名1`)单引号必须是波浪线单引号
(`名1`)单引号不加也可以(名1)
17. create table if not exists qqqq(名1 int,名2 varchar(20),名3 varchar(20),名4 int,名5 date,primary key(名1))default charset=utf8;
//if not esists /表示如果有相同名字的话,会显示警告,不能创建!!
/如没有相同名字则直接创建
18. create table www(名1 int primary key auto_increment,名2 varchar(20),名3 varchar(20),名4 int,名5 date)default charset=utf8;
insert into oo(名2,名3,名4,名5)values("小米","男",99,now());
//自身名1(id)加1;
//自增只能用于数字类型
insert into o(名1,名2,名3,名4,名5)values(2,"小米","男",99,now());
//从2开始
21. create table ff(id int primary key auto_increment,title varchar(20) not null,author varchar(20) not null,date date)default charset=utf8;
title varchar(20) // 后面加 not null
//让字段名不为空
insert into //插入 写入
values //数值
where //
alter //改变
change //改变,变换
person order
modify integer //修改整数
not null
alter table table-name drop col-name;
增加列(单列)
alter table table-name add col-name col-type comment 'xxx';
增加列(多列)
alter table table-name add col-name col-type comment 'xxx', add col-name col-type(col-length) comment 'xxx';
增加表字段并指明字段放置为第一列
alter table table-name add col-name col-type COMMENT 'sss' FIRST;
增加表字段并指明字段放置为特定列后面
alter table table-name add col-name col-type after col-name-1;
使用MODIFY修改字段类型
alter table table-name modify column col-name col-type;
使用CHANGE修改字段类型
alter table table-name change col-name col-name col-type;
使用CHANGE修改字段名称
alter table table-name change old-col-name new-col-name col-type;
修改列类型、长度
alter table table-name change old-col-name new-col-name new-col-type;
查看表中列属性
show columns from table-name;
修改表名
rename table old-table-name to new-table-name;
为字段设置NULL和DEFAULT
alter table table-name modify col-name col-type not null default 100;
修改字段的默认值
alter table table-name alter col-name set default 10000;
字段删除默认值
alter table table-name alter col-name drop default;
干货|app自动化测试之设备交互API详解
干货|app自动化测试之Appium问题分析及定位
干货| app自动化测试之Andriod微信小程序的自动化测试
如果你也有这些职场困惑,周六一直线上答疑
文末福利 | 团队管理第一步之高效招聘
精准化测试原理简介与实践探索
文末有福利 | 面试时如何命中面试官的考题?
Visual studio prebuild/postbuild 设置条件不生效
使用腾讯地图api获取定位信息经纬度(需要浏览器支持,且需要https)
- 最新文章
-
CVPR 之 老照片修复
软件开发汇总
音视频处理、图像处理、图像识别和字符识别全能库JavaCV完整教程(包含完整JavaCV入门、JavaCV实战、ffmpeg、opencv和tesserac教程)
《JavaCV音视频开发宝典》专栏介绍和目录
如何跨平台调用ffmpeg?史上最简单基于JavaCV跨平台执行ffmpeg命令
JavaCV入门指南教程目录
JavaCV免费教程大全(完整JavaCV人脸检测、训练、识别和音视频入门和实战教程)
「日志」Navicat统计的行数竟然和表实际行数不一致
「开源组件」青龙定时面板使用场景举例
「实用」打造自我感觉非常漂亮的Mac终端
- 热门文章
-
隐私计算相关技术介绍
A Distributed Sandbox for Untrusted Computation on Secret Data 阅读笔记
网络安全协议之IPsec
线性规划之单纯形算法矩阵描述与python实现
The Chubby lock service for looselycoupled distributed systems 阅读笔记
raft共识算法
DDTP 分布式数据传输协议白皮书
段恢复与写前日志SegmentBased Recovery Writeahead logging revisited
干货|接口测试必备技能常见接口协议解析Selenium | PageObject原则
Selenium | PageObject原则