想要一些意见是最佳方式。
因此,我正在为比赛创建一个系统,类似于足球/足球等体育运动的方式等。
目前我有一个赛季,一个赛季然后有很多球队,一个球队可以有很多会员。
一个赛季有很多比赛,其中所有队伍将始终参加每场比赛,但并非所有队员都参加比赛。
存储团队成员参加比赛的最佳方式是什么?
目前我只考虑比赛表和成员之间的一个支点,但是这并不表示该成员属于哪个团队,而成员可以属于许多团队。你有3路数据透视表吗?
继承我当前的表结构
CREATE TABLE `seasons` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`archived` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE `teams` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`season_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `teams_season_id_index` (`season_id`),
CONSTRAINT `teams_season_id_foreign` FOREIGN KEY (`season_id`) REFERENCES `seasons` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE `members` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`display_name` varchar(12) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `members_display_name_unique` (`display_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE `members_teams` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`member_id` int(10) unsigned NOT NULL,
`team_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `members_teams_member_id_index` (`member_id`),
KEY `members_teams_team_id_index` (`team_id`),
CONSTRAINT `members_teams_member_id_foreign` FOREIGN KEY (`member_id`) REFERENCES `members` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `members_teams_team_id_foreign` FOREIGN KEY (`team_id`) REFERENCES `teams` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE `competitions` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`start_at` datetime NOT NULL,
`end_at` datetime NOT NULL,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`skill` int(11) NOT NULL,
`season_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `competitions_season_id_index` (`season_id`),
CONSTRAINT `competitions_season_id_foreign` FOREIGN KEY (`season_id`) REFERENCES `seasons` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
答案 0 :(得分:0)
我会有一个players
表格,以便玩家的信息与任何团队信息分开。那么你可能有一个competition_players
表或类似表,它有三个外键:团队ID,玩家ID和竞争ID,所以你可以看到谁在每场比赛中为哪支球队效力。