交友类软件数据库建表语句
时间: 2023-11-11 21:55:03 浏览: 73
以下是一个可能的交友类软件的数据库建表语句,仅供参考:
用户表:
CREATE TABLE users (
id INT(11) PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(50) NOT NULL,
password VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
gender ENUM('male', 'female', 'other') NOT NULL,
date_of_birth DATE NOT NULL,
location VARCHAR(255) NOT NULL,
bio TEXT,
profile_picture VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
好友关系表:
CREATE TABLE friendships (
id INT(11) PRIMARY KEY AUTO_INCREMENT,
user_id INT(11) NOT NULL,
friend_id INT(11) NOT NULL,
status ENUM('pending', 'accepted', 'rejected') NOT NULL DEFAULT 'pending',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (friend_id) REFERENCES users(id)
);
聊天记录表:
CREATE TABLE chat_messages (
id INT(11) PRIMARY KEY AUTO_INCREMENT,
sender_id INT(11) NOT NULL,
recipient_id INT(11) NOT NULL,
message TEXT NOT NULL,
sent_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (sender_id) REFERENCES users(id),
FOREIGN KEY (recipient_id) REFERENCES users(id)
);
照片表:
CREATE TABLE photos (
id INT(11) PRIMARY KEY AUTO_INCREMENT,
user_id INT(11) NOT NULL,
url VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id)
);
喜欢的用户表:
CREATE TABLE likes (
id INT(11) PRIMARY KEY AUTO_INCREMENT,
user_id INT(11) NOT NULL,
liked_user_id INT(11) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (liked_user_id) REFERENCES users(id)
);
阅读全文