由于数据库的设计经验不足,加上知识体系不完善,数据库分析能力不够,导致上一版(http://www.cnblogs.com/qiangzai/p/8032833.html)设计错误颇多;这一次经过了我的深思熟虑,将数据库进行了很大的调整,希望能在以后的学习中继续改善和修补。
E-R图如下:
本项目使用MYSQL创建一个数据库game_db,其中包括四张表,分别是用户登录信息表(accountinfo),用户详细信息表(individual_info),用户分数表(gamescoreinfo),房间信息表(house):
accountinfo表:
属性名称 |
数据类型 |
属性描述 |
UserID |
int |
用户ID |
GameID |
int |
游戏ID |
Account |
Varchar(45) |
玩家名 |
Password |
Varchar(45) |
密码 |
MemberOrder |
Int |
会员等级 |
Individual_info表:
属性名称 |
数据类型 |
属性描述 |
UserID |
int |
用户ID |
Really_name |
Varchar(45) |
真实姓名 |
Sex |
Varchar(10) |
性别 |
|
Varchar(45) |
QQ号 |
Phone |
Varcher(45) |
电话号码 |
|
Varchar(45) |
邮箱地址 |
Gamescoreinfo表:
属性名称 |
数据类型 |
属性描述 |
GameID |
int |
游戏ID |
HouseID |
Int |
房间ID |
Score |
Int |
游戏分数 |
WinCount |
Varchar(45) |
胜利局数 |
LostCount |
Varchar(45) |
输局数 |
DrawCount |
Varchar(45) |
和局数 |
RunCount |
Varchar(45) |
逃跑局数 |
house表:
属性名称 |
数据类型 |
属性描述 |
HouseID |
Int |
房间ID |
housename |
Varchar(45) |
房间号 |
EnterTime |
Varchar(45) |
进入时间 |
LeaveTime |
Varchar(45) |
离开时间 |
建库,表和插入数据SQL语句:
CREATE SCHEMA `game_db` ;
CREATE TABLE `game_db`.`accountsinfo` (
`UserID` INT NOT NULL AUTO_INCREMENT,
`GameID` INT NOT NULL,
`Account` VARCHAR(45) BINARY NOT NULL,
`Password` VARCHAR(45) BINARY NULL DEFAULT 0,
`Sex` VARCHAR(10) NOT NULL DEFAULT ‘nan‘,
`MemberOrder` INT NOT NULL,
UNIQUE INDEX `Account_UNIQUE` (`Account` ASC));
SELECT * FROM game_db.accountsinfo;
INSERT INTO `game_db`.`accountsinfo` (`UserID`, `GameID`, `Account`, `Password`, `MemberOrder`) VALUES (‘1‘, ‘1‘, ‘LiMing‘, ‘123‘, ‘1‘);
INSERT INTO `game_db`.`accountsinfo` (`UserID`, `GameID`, `Account`, `Password`, `MemberOrder`) VALUES (‘2‘, ‘2‘, ‘Bob‘, ‘111‘, ‘2‘);
INSERT INTO `game_db`.`accountsinfo` (`UserID`, `GameID`, `Account`, `Password`, `MemberOrder`) VALUES (‘3‘, ‘3‘, ‘qinagzai‘, ‘222‘, ‘5‘);
INSERT INTO `game_db`.`accountsinfo` (`UserID`, `GameID`, `Account`, `Password`, `MemberOrder`) VALUES (‘4‘, ‘4‘, ‘jier‘, ‘333‘, ‘4‘);
INSERT INTO `game_db`.`accountsinfo` (`UserID`, `GameID`, `Account`, `Password`, `MemberOrder`, `AccountsInfocol`) VALUES (‘5‘, ‘5‘, ‘lucy‘, ‘1234‘, ‘7‘, ‘1‘);
CREATE TABLE `game_db`.`individual_info` (
`UserID` INT NOT NULL,
`Really_name` VARCHAR(45) NOT NULL,
`Sex` VARCHAR(10) NOT NULL,
`QQ` VARCHAR(45) NOT NULL,
`Phone` VARCHAR(45) NOT NULL,
`Email` VARCHAR(45) NOT NULL,
PRIMARY KEY (`UserID`));
SELECT * FROM game_db.individual_info;
INSERT INTO `game_db`.`individual_info` (`UserID`, `Really_name`, `QQ`, `Sex`,`Phone`, `Email`) VALUES (‘1‘, ‘AA‘, ‘12345677‘,`nan`, ‘13177789865‘, ‘[email protected]‘);
INSERT INTO `game_db`.`individual_info` (`UserID`, `Really_name`, `QQ`, `Sex`,`Phone`, `Email`) VALUES (‘2‘, ‘BB‘, ‘1223453‘, `nan`, ‘17738724089‘, ‘[email protected]‘);
INSERT INTO `game_db`.`individual_info` (`UserID`, `Really_name`, `QQ`, `Sex`,`Phone`, `Email`) VALUES (‘3‘, ‘CC‘, ‘45665654‘, `nan`, ‘17890762354‘, ‘[email protected]‘);
INSERT INTO `game_db`.`individual_info` (`UserID`, `Really_name`, `QQ`, `Sex`,`Phone`, `Email`) VALUES (‘4‘, ‘DD‘, ‘344245345‘, `nan`, ‘13798082376‘, ‘[email protected]‘);
INSERT INTO `game_db`.`individual_info` (`UserID`, `Really_name`, `QQ`,`Sex`, `Phone`, `Email`) VALUES (‘5‘, ‘EE‘, ‘5645665‘, `nan`, ‘197662762‘, ‘[email protected]‘);
CREATE TABLE `game_db`.`gamescoreinfo` (
`GameID` INT NOT NULL AUTO_INCREMENT,
`Score` INT NOT NULL DEFAULT 0,
`WinCount` VARCHAR(45) NOT NULL DEFAULT 0,
`LostCount` VARCHAR(45) NOT NULL DEFAULT 0,
`DrawCount` VARCHAR(45) NOT NULL DEFAULT 0,
`RunCount` VARCHAR(45) NOT NULL DEFAULT 0,
PRIMARY KEY (`GameID`));
SELECT * FROM game_db.gamescoreinfo;
INSERT INTO `game_db`.`gamescoreinfo` (`GameID`, `Score`, `WinCount`, `LostCount`, `DrawCount`, `RunCount`) VALUES (‘1‘, ‘7‘, ‘3‘, ‘2‘, ‘4‘);
INSERT INTO `game_db`.`gamescoreinfo` (`GameID`, `Score`, `WinCount`, `LostCount`, `DrawCount`, `RunCount`) VALUES (‘2‘, ‘7‘, ‘3‘, ‘2‘, ‘4‘);
INSERT INTO `game_db`.`gamescoreinfo` (`GameID`, `Score`, `WinCount`, `LostCount`, `DrawCount`, `RunCount`) VALUES (‘3‘, ‘7‘, ‘3‘, ‘2‘, ‘4‘);
INSERT INTO `game_db`.`gamescoreinfo` (`GameID`, `Score`, `WinCount`, `LostCount`, `DrawCount`, `RunCount`) VALUES (‘4‘, ‘7‘, ‘3‘, ‘2‘, ‘4‘);
INSERT INTO `game_db`.`gamescoreinfo` (`GameID`,`Score`, `WinCount`, `LostCount`, `DrawCount`, `RunCount`) VALUES (‘5‘, ‘7‘, ‘3‘, ‘2‘, ‘4‘);
CREATE TABLE `game_db`.`house` (
`HouseID` INT NOT NULL AUTO_INCREMENT,
`houseID` VARCHAR(45) NOT NULL,
`EnterTime` VARCHAR(45) NOT NULL DEFAULT 0,
`LeaveTime` VARCHAR(45) NOT NULL,
PRIMARY KEY (`HouseID`));
SELECT * FROM game_db.house;
INSERT INTO `game_db`.`house` (`UserID`, `houseID`, `EnterTime`, `LeaveTime`) VALUES (‘1‘, ‘1‘, ‘12‘, ‘345‘);
欢迎大家批评指正