基于ssm的个人博客数据库设计MySQL
时间: 2025-01-02 21:45:55 浏览: 10
基于SSM(Spring MVC + MyBatis + Spring JDBC)的个人博客数据库设计通常会涉及几个关键部分:
1. **用户表** (User):存储博主的基本信息,如id(主键)、username、password、email等。
```sql
CREATE TABLE `users` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`username` VARCHAR(50) NOT NULL UNIQUE,
`password` VARCHAR(64) NOT NULL,
`email` VARCHAR(100),
`create_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
```
2. **文章表** (BlogPost):包含文章标题、内容、作者ID、创建日期等字段。
```sql
CREATE TABLE `blog_posts` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`title` VARCHAR(200) NOT NULL,
`content` TEXT,
`author_id` INT,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (`author_id`) REFERENCES users(`id`)
);
```
3. **分类表** (Category) 和 **标签表** (Tag):可以用于文章的组织和索引,例如:
```sql
CREATE TABLE `categories` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR(50) NOT NULL
);
CREATE TABLE `post_categories` (
`post_id` INT,
`category_id` INT,
PRIMARY KEY (`post_id`, `category_id`),
FOREIGN KEY (`post_id`) REFERENCES blog_posts(`id`),
FOREIGN KEY (`category_id`) REFERENCES categories(`id`)
);
CREATE TABLE `tags` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR(50) NOT NULL
);
CREATE TABLE `post_tags` (
`post_id` INT,
`tag_id` INT,
PRIMARY KEY (`post_id`, `tag_id`),
FOREIGN KEY (`post_id`) REFERENCES blog_posts(`id`),
FOREIGN KEY (`tag_id`) REFERENCES tags(`id`)
);
```
阅读全文