我有一个从以下SELECT语句调用的视图:
SELECT [Position], [TeamName], [Played], [Wins], [Loss], [Draws], [Points], [Goals_Scored], [Goals_Against], [Goal_Difference], [LeagueID]
FROM League_Table
WHERE LeagueID = @LeagueID
ORDER BY Points DESC, Goal_Difference DESC;
这将输出如下所示的联赛表。
我有一个if语句,用于检查是否达到了每个团队的总匹配数(这意味着赛季结束),然后(这是我坚持的部分),只需刷新表,一切都重新开始
IF (SELECT MIN(Played) FROM dbo.League_Table WHERE LeagueID = @LeagueID) > @TotalMatches
我的问题是重置联赛桌的最佳方法是什么?下面是刷新后的示例:
答案 0 :(得分:2)
如果此表具有大量数据,我认为插入新表并重新插入此表将更快地执行:
sp_rename dbo.League_Table, dbo.League_Table_old; -- rename old table
CREATE TABLE dbo.League_Table AS (.....); -- create same table
INSERT INTO dbo.League_Table
SELECT t.leagueID,t.teamName,0,0,0,0,0,null,null,null
FROM dbo.League_Table_old t --insert values to new table