54 lines
2.5 KiB
SQL
54 lines
2.5 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) VALUES('测试1','2022-05-10 16:52:09','测试测试','测试测试测试测试','默认');
|
|
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','测试测试','测试测试测试测试','默认');
|
|
-- 评论表: 评论ID、文章ID、评论内容、发布时间、评论者IP
|
|
create table comment
|
|
(
|
|
id int(10) PRIMARY KEY AUTO_INCREMENT,
|
|
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 |