mysql

cmd命令

net start mysql80   启动mysql

mysql -uroot -p1235456 进入(可以设置默认密码 )

exit 退出

show databases 展示数据库 (有四个自带的 不要删 information_schema    mysql   
 performance_schema     sys)

use 数据名;

select * from 表;表中数据

create database 名称 ;生成数据库

 drop database 名称;删除数据库

desc 表格;展示表格

create table play(
    -> id int,
    -> name varchar(10),
    -> gold decimal(10,2));创建表

表的类型设置;

 alter table 表 modify column 索引(field) varchar(100);   修改列 后可跟默认值

alter  table 表 rename column 原索引名 to 改后名;         改名

 alter  table 表 add column 索引名 索引类型;                   添加

 alter table 表 drop column 索引;                                      删除

  alter table 表名 modify 表单 表单类型 default 值;      修改默认值

修改的默认值会在插入后生效;(最好建表时使用)

alter  table 名 add constraint pk_stuid primary key(stuid);主键约束[pri]

可以有好多但是只能说一个 一个主键连接了两个索引

唯一键可以有好多 

alter table student add constraint uk_stuname unique(stuname);唯一约束[uni]

检查约束
alter table student add constraint ck_age check(age between 0 and 100);
alter table student add constraint ck_age check(age>=0 and age<=100);
alter table student add constraint ck_password check(password.length>6);
alter table student add constraint ck_password check(sex='男' or sex ='女');

主键约束可以约束多个 不允许重复

alter table student add constraint fk_student_grade foalter table student modify column address

内联

alter table student modify column address varchar(200) default 'dzbx';默认加改格式

表的数据

insert into student (name,height) values (2,155),(3,166),(4,177);

添加数据 以及一次添加多个数据

varchar类型数据加''''''''''

updateset 数据名=值 where 索引数据名=suoyin  单个改值

updateset 数据名=值                                            修改所有(去掉where)

delete from 表名 where height is null;                       nul不能用=    ""表示空字符

where 限制内容       每次搜索都是在全部的基础上进行的

and or not            and 连接多个索引名=值                                        优先级not>or>and

(betwen and是一体的not也无法影响)

in    相当与=  (里面可以放多个值)        减少了写多个索引名

butween  值1 and 值2      (从值1到值2的范围)

link 模糊查询   %任意个字符 _任意一个字符[放在表单后边 好像都是 但写错了一次]

regexp 正则 与like 信似 用来缩减范围 放where后边

排序 select * from 表名  order by 表头     按照表头排序 升序;

后边加desc 是降序;后可跟另一个属性 进行排序 asc 升序group by 属性 按照来分组   后常跟having 进行筛选  后再跟order by 进行排序

'不对称 问题打一个';结束即可出来substr 截取 最后一个是长度  limit(分页查询原理union) 显示前三名 也可以写两个值 第一个表示偏移量 第二个是长度

union 合并两条查询  符合要求重复会只显示1个 union all会全部出现[并集]

intersect {交集} 只有重复的;

except {差集}只符合两条查询语句中的一条

算数方法()里面写值

ceil()向上取整,

floor()向下取整,

rand()随机数

round()四舍五入

power()幂

sqrt()算数根

abs()绝对值

sign()标记 值是-1 0 1

字符方法()里面写字符

concat(,,,,,)拼接

insert()截取添加

lower()转小写

upper()转大写

substring()截取

left()左边截取

right()右边截取

length()字节数

char_length()字符数

replace('','','')换值

locate( 小,大)算下标 从1开始

instr(大,小)算下标  从1开始

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值