63 lines
3.0 KiB
SQL
63 lines
3.0 KiB
SQL
create DATABASE pro_blog;
|
|
|
|
use pro_blog;
|
|
|
|
-- 用户登录表: 登录信息ID、登录时间、登录IP、客户端标识、有效期
|
|
|
|
create table login(
|
|
id int(10) PRIMARY KEY AUTO_INCREMENT,
|
|
login_time datetime not null,
|
|
-- xxx.xxx.xxx.xx -> ipv4
|
|
-- xxxx:xxxx:xxxx::xxxx -> ipv6
|
|
ip varchar(40) not null,
|
|
client varchar(200) null,
|
|
expire_time datetime null
|
|
);
|
|
|
|
-- 文章表: 文章ID、标题、封面、发布时间、描述(一部分的文章内容)、文章内容、分类、阅读量、评论数、状态
|
|
|
|
create table article(
|
|
id int(10) PRIMARY KEY AUTO_INCREMENT,
|
|
title varchar(50) not null,
|
|
cover varchar(200) null,
|
|
publish_time datetime null,
|
|
description varchar(500) null,
|
|
content text not null,
|
|
category varchar(20) not null,
|
|
view_count int default 0,
|
|
comment_count int default 0,
|
|
status tinyint(1) default 1 -- 状态 1标识已发布 2表示草稿 0表示已删除
|
|
);
|
|
INSERT INTO article(title,publish_time,description,content,category,cover) VALUES('测试1','2022-05-10 16:52:09','测试测试','测试测试测试测试','默认','https://www.liulinblog.com/wp-content/uploads/2022/05/1652233699-97014b5f43a5d59-300x200.webp');
|
|
INSERT INTO article(title,publish_time,description,content,category) VALUES('测试2','2022-05-10 16:52:09','测试测试','测试测试测试测试','默认');
|
|
INSERT INTO article(title,publish_time,description,content,category) VALUES('测试3','2022-05-10 16:52:09','测试测试','测试测试测试测试','默认');
|
|
INSERT INTO article(title,publish_time,description,content,category) VALUES('测试4','2022-05-10 16:52:09','测试测试','测试测试测试测试','默认');
|
|
INSERT INTO article(title,publish_time,description,content,category) VALUES('测试5','2022-05-10 16:52:09','测试测试','测试测试测试测试','默认');
|
|
INSERT INTO article(title,publish_time,description,content,category) VALUES('测试6','2022-05-10 16:52:09','测试测试','测试测试测试测试','默认');
|
|
INSERT INTO article(title,publish_time,description,content,category) VALUES('测试7','2022-05-10 16:52:09','测试测试','测试测试测试测试','默认');
|
|
|
|
|
|
update article set cover = 'https://shadow.elemecdn.com/app/element/hamburger.9cf7b091-55e9-11e9-a976-7f4d0b07eef6.png'
|
|
where cover is null;
|
|
-- 评论表: 评论ID、文章ID、评论内容、发布时间、评论者IP
|
|
create table comment
|
|
(
|
|
id int(10) PRIMARY KEY AUTO_INCREMENT,
|
|
nickname varchar(20) null,
|
|
email varchar(50) null,
|
|
article_id int(10) not null,
|
|
content varchar(500) not null,
|
|
publish_time datetime not null,
|
|
ip varchar(40) not null
|
|
);
|
|
|
|
-- 分页查询
|
|
select * from article limit 4; -- 只查询4条
|
|
select * from article limit 0,2; -- 第1页
|
|
select * from article limit 2,2; -- 第2页
|
|
select * from article limit 4,2; -- 第3页
|
|
-- 假设条数位:size 页码为: page
|
|
-- 那么分页的起始位置为: (page - 1) * size
|
|
-- 搜索文章
|
|
select id,title,category,publish_time,cover,description,view_count,comment_count
|
|
from article where title like '%测试%' or content like '%测试%'; |