帮我写一份mysql脚本语言完成上面数据库的创建
时间: 2024-12-25 15:30:39 浏览: 12
当然可以,以下是使用MySQL命令行或SQL文件创建上述数据库结构的脚本示例。请注意,你需要先连接到MySQL服务器并选择你要操作的数据库(这里假设数据库名为`basketball_management`)。
```sql
DELIMITER $$
CREATE DATABASE basketball_management; -- 创建新的数据库
USE basketball_management; -- 切换到新数据库
CREATE TABLE Teams (
TeamID INT AUTO_INCREMENT PRIMARY KEY,
TeamName VARCHAR(255) NOT NULL,
School VARCHAR(255),
EstablishmentDate DATE,
CoachID INT,
FOREIGN KEY (CoachID) REFERENCES Coaches(CoachID)
);
CREATE TABLE Coaches (
CoachID INT AUTO_INCREMENT PRIMARY KEY,
CoachName VARCHAR(255) NOT NULL,
Age INT,
FOREIGN KEY (TeamID) REFERENCES Teams(TeamID) ON DELETE CASCADE
);
CREATE TABLE Players (
PlayerID INT AUTO_INCREMENT PRIMARY KEY,
TeamID INT,
playerName VARCHAR(255) NOT NULL,
Gender ENUM('Male', 'Female'),
Age INT,
Height DECIMAL(5,2),
Weight DECIMAL(5,2),
FOREIGN KEY (TeamID) REFERENCES Teams(TeamID)
);
CREATE TABLE Venues (
VenueID INT AUTO_INCREMENT PRIMARY KEY,
Capacity INT,
Location VARCHAR(255)
);
CREATE TABLE TrainingSessions (
SessionID INT AUTO_INCREMENT PRIMARY KEY,
TeamID INT,
VenueID INT,
StartTime DATETIME,
EndTime DATETIME,
FOREIGN KEY (TeamID) REFERENCES Teams(TeamID),
FOREIGN KEY (VenueID) REFERENCES Venues(VenueID)
);
CREATE TABLE Judges (
JudgeID INT AUTO_INCREMENT PRIMARY KEY,
Name VARCHAR(255) NOT NULL,
Age INT,
Rank ENUM('Junior', 'Senior')
);
CREATE TABLE Matches (
MatchID INT AUTO_INCREMENT PRIMARY KEY,
HomeTeamID INT,
AwayTeamID INT,
VenueID INT,
RefereeID INT,
ScoreHomeTeam INT,
ScoreAwayTeam INT,
FOREIGN KEY (HomeTeamID) REFERENCES Teams(TeamID),
FOREIGN KEY (AwayTeamID) REFERENCES Teams(TeamID),
FOREIGN KEY (RefereeID) REFERENCES Judges(JudgeID)
);
CREATE TABLE People (
PersonID INT AUTO_INCREMENT PRIMARY KEY,
Name VARCHAR(255),
Type ENUM('Player', 'Coach', 'Judge'),
UNIQUE (Name, Type) -- 通过姓名和类型防止重复
);
$$
DELIMITER ;
-- 执行完后记得运行此脚本
```
执行上述脚本后,你将拥有符合需求的比赛信息管理系统的数据库结构。
阅读全文