数据库基础知识

一,mysql建表:

PK:primary key 主键,唯一

NN:not null       非空

UQ:unique   联合主键,唯一

AI:auto increment 自增

BIN:二进制

UN:unsigned  整数

二,基本sql语句

use myblog;

-- show tables

-- insert into users(username,`password`,realname) values('lisi','1213','李四2')
--查询总数 / 分页 select count(id) as sum from blogs select * from blogs order by id desc limit 2 offset 2

-- select id, username from users -- select * from users where password like '%1%' order by id desc -- SET SQL_SAFE_UPDATES = 0 -- select * from blogs -- update blogs set title='鱿鱼博客', content = '878j....' where id = 3 -- insert into blogs(title,content,createtime,author) values('博客名称B','content2','86753465789','llq')

三,外键

1,创建外键

2,更新限制 & 删除及联

3,连表查询

select blogs.*, users.username,users.nickname 
from blogs inner join users on blogs.userid = users.id //此处与外键没关系
where users.username = '林连强'

数据模型设计

 

 

posted @ 2020-09-10 19:40  毛栗的demo  阅读(86)  评论(0)    收藏  举报