博客
关于我
丛林战争游戏数据库设计
阅读量:90 次
发布时间:2019-02-26

本文共 1997 字,大约阅读时间需要 6 分钟。

目前游戏的数据库设计较为简单,包含两个表

用户信息表User

用来存放玩家数据

  1. username 玩家用户名
  2. password 用户密码
  3. id 主键,自动增长

客户端登录时,验证用户名和密码是否存在于数据库,存在说明用户存在,允许登录,返回登录成功,不能存则返回失败。

CREATE TABLE `Game`.`user`  (  `id` int(10) NOT NULL AUTO_INCREMENT,  `username` varchar(50) NOT NULL,  `password` varchar(50) NOT NULL,  PRIMARY KEY (`id`),  UNIQUE INDEX `unique_username`(`username`));

数据表Result

用来存放玩家的战绩

  1. id 主键
  2. userid 外键 表示战绩属于哪个用户的
  3. totalCount总场数
  4. winCount胜利局数
CREATE TABLE `Game`.`result`  (  `id` int(10) NOT NULL AUTO_INCREMENT,  `userid` int(10) NOT NULL COMMENT '表示战绩属于哪个玩家',  `totalcount` int NULL DEFAULT 0 COMMENT '一共游戏局数,默认为0',  `wincount` int NOT NULL DEFAULT 0 COMMENT '游戏胜利局数',  PRIMARY KEY (`id`),  CONSTRAINT `fk_userid` FOREIGN KEY (`userid`) REFERENCES `Game`.`user` (`id`));

sql文件Game.sql

/* Navicat Premium Data Transfer Source Server         : JungleWars Source Server Type    : MySQL Source Server Version : 80018 Source Host           : localhost:3306 Source Schema         : Game Target Server Type    : MySQL Target Server Version : 80018 File Encoding         : 65001 Date: 11/07/2020 01:42:07*/SET NAMES utf8mb4;SET FOREIGN_KEY_CHECKS = 0;-- ------------------------------ Table structure for result-- ----------------------------DROP TABLE IF EXISTS `result`;CREATE TABLE `result` (  `id` int(10) NOT NULL AUTO_INCREMENT,  `userid` int(10) NOT NULL COMMENT '表示战绩属于哪个玩家',  `totalcount` int(11) DEFAULT '0' COMMENT '一共游戏局数,默认为0',  `wincount` int(11) NOT NULL DEFAULT '0' COMMENT '游戏胜利局数',  PRIMARY KEY (`id`),  KEY `fk_userid` (`userid`),  CONSTRAINT `fk_userid` FOREIGN KEY (`userid`) REFERENCES `user` (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;-- ------------------------------ Table structure for user-- ----------------------------DROP TABLE IF EXISTS `user`;CREATE TABLE `user` (  `id` int(10) NOT NULL AUTO_INCREMENT,  `username` varchar(50) NOT NULL,  `password` varchar(50) NOT NULL,  PRIMARY KEY (`id`),  UNIQUE KEY `unique_username` (`username`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;SET FOREIGN_KEY_CHECKS = 1;

转载地址:http://xdok.baihongyu.com/

你可能感兴趣的文章
MYSQL8.0以上忘记root密码
查看>>
Mysql8.0以上重置初始密码的方法
查看>>
mysql8.0新特性-自增变量的持久化
查看>>
Mysql8.0注意url变更写法
查看>>
Mysql8.0的特性
查看>>
MySQL8修改密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
查看>>
MySQL8修改密码的方法
查看>>
Mysql8在Centos上安装后忘记root密码如何重新设置
查看>>
Mysql8在Windows上离线安装时忘记root密码
查看>>
MySQL8找不到my.ini配置文件以及报sql_mode=only_full_group_by解决方案
查看>>
mysql8的安装与卸载
查看>>
MySQL8,体验不一样的安装方式!
查看>>
MySQL: Host '127.0.0.1' is not allowed to connect to this MySQL server
查看>>
Mysql: 对换(替换)两条记录的同一个字段值
查看>>
mysql:Can‘t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock‘解决方法
查看>>
MYSQL:基础——3N范式的表结构设计
查看>>
MYSQL:基础——触发器
查看>>
Mysql:连接报错“closing inbound before receiving peer‘s close_notify”
查看>>
mysqlbinlog报错unknown variable ‘default-character-set=utf8mb4‘
查看>>
mysqldump 参数--lock-tables浅析
查看>>