用SQL语句写个人理财APP的数据库设计
时间: 2023-09-28 09:11:04 浏览: 71
数据库课程设计.rar
好的,下面是一个基于SQL语句的个人理财APP的数据库设计:
1. 用户表(user)
```
CREATE TABLE user (
id INT NOT NULL AUTO_INCREMENT,
username VARCHAR(50) NOT NULL,
password VARCHAR(50) NOT NULL,
phone_number VARCHAR(20) NOT NULL,
email VARCHAR(50) NOT NULL,
balance DECIMAL(10,2) NOT NULL DEFAULT 0,
PRIMARY KEY (id)
);
```
2. 支出分类表(expense_category)
```
CREATE TABLE expense_category (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
user_id INT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (user_id) REFERENCES user(id)
);
```
3. 收入分类表(income_category)
```
CREATE TABLE income_category (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
user_id INT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (user_id) REFERENCES user(id)
);
```
4. 支出记录表(expense_record)
```
CREATE TABLE expense_record (
id INT NOT NULL AUTO_INCREMENT,
amount DECIMAL(10,2) NOT NULL,
date DATE NOT NULL,
remark VARCHAR(100),
category_id INT NOT NULL,
user_id INT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (category_id) REFERENCES expense_category(id),
FOREIGN KEY (user_id) REFERENCES user(id)
);
```
5. 收入记录表(income_record)
```
CREATE TABLE income_record (
id INT NOT NULL AUTO_INCREMENT,
amount DECIMAL(10,2) NOT NULL,
date DATE NOT NULL,
remark VARCHAR(100),
category_id INT NOT NULL,
user_id INT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (category_id) REFERENCES income_category(id),
FOREIGN KEY (user_id) REFERENCES user(id)
);
```
以上是一个基于SQL语句的个人理财APP的数据库设计方案,您可以根据需要进行修改和完善。
阅读全文