MySql数据库总结

主键(Primary Key):在表中的唯一标识,不能重复,但可以用两个字段来作为主键,比如userName和password组合起来作为主键

外键(Foreign Key):这列数据引用了另外一个表的主键

Unique Key(UK):表示该项不能重复,允许一条可以为null

Not Null(NN):不为空

AI:自动增长

UQ:不能重复


最后一行自己设定的是默认的格式

在数据库中字符串是用varchar(45)表示的,45表示字符串大小


desc tablename 查看表结构

select * from mytable查询表中所有列,也即查询整个表结构

select * from mytable limit 3,4表示从该表第三行往下4行的所有数据

select * from mytable order by id 根据id排序

select * from mytable order by id desc根据id反序排序

select * from mytable order by id desc limit 1根据id反序排序并且取第一条

select replace(first name,'d','1') from actor  从actor表中将first name表中的d换成1

select * from categroy where (name='animation' or id=1) and name='new'  当有多个条件优先级易混淆时,最好加上括号避免出错

select * from mytable where id in(1,4,7) 取出mytable中id含有1,4,7的所有数据

select * from mytable where id between 1 and 9 取出1到9之间的数据

select * from mytable where name like 'A%'  取出表中name列中以A开头的所有数据,关键字like和%要注意

select * from mytable where name like 'A_'  取出表中name列中以A开头并且只有2个字母,第二个字母为任意字符

select * from mytable where name like '%A%'  取出表中name列中包含A的数据

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值