所以我在这里看到的有点矛盾,因为局限并不是间接地真正地直接构成游戏的属性。但是也许就是我。我个人建议使用类似RunsScored表的表,并将其链接回某种形式的GamesHeader表,因此请考虑:
CREATE TABLE GamesHeader (
GameID INT IDENTITY(1,1),
HomeTeamID INT, --FK to teams table, naturally
AwayTeamID INT, --FK to teams table, naturally
FinalInningsCount BYTE, -- for faster reporting after the game is over
FinalHomeScore BYTE, -- for faster reporting after the game is over
FinalAwayScore BYTE, -- for faster reporting after the game is over
--Other attribs
)
CREATE TABLE RunsScored (
RunsScoredID BIGINT IDENTITY(1,1), -- for faster reverse traversal, possibly. May not be needed, this depends on your setup, as the normalization will show a composite key anyways
PlayerID INT, --FK to players table naturally
GameID INT, --FK to GamesHeader table naturally
Inning BYTE, --wait for the payoff
RunsEarned, --because you may want to track this by the player ... really the problem is that there's not a single naturalized setup for this, so you may be intersecting this table to another stats table elsewhere. idk, it depends on your model. I'm going for fairly simplistic atm. Wanted to demonstrate something else entirely, but this needs to be accounted for.
-- other attribs
)
SELECT MAX(r.Inning) FROM RunsScored r JOIN GamesHeader g ON g.GameID = r.GameID WHERE GameID = 'x'
这将为您提供特定游戏的最大局限性,如果需要,您可以通过PlayerID-> TeamID进一步完善以找出更多细节。我不确定那些可能是什么。
我实际上可能会优化第二张表,而不是RunsScored,而是关于AtBat的东西,因为这正是您要跟踪的内容。我只是想说明如何从游戏桌中取消局数的标准化。我将模型调整为像我的项目那样流动。HTH。YMMV。
另请注意,我是TSQL专家,但我认为以下表达的概念可以很好地解释我的概念。语言语义可能不会对齐。