Updated foreign keys in tables.
This commit is contained in:
parent
50c68ef268
commit
9ba8a99e82
2 changed files with 66 additions and 13 deletions
|
@ -1,3 +1,32 @@
|
||||||
|
------ DROP ALL TABLES ------
|
||||||
|
--
|
||||||
|
-- Courtesy of: https://stackoverflow.com/questions/8439650/how-to-drop-all-tables-in-a-sql-server-database
|
||||||
|
--
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
|
--DECLARE @Sql NVARCHAR(500) DECLARE @Cursor CURSOR
|
||||||
|
|
||||||
|
--SET @Cursor = CURSOR FAST_FORWARD FOR
|
||||||
|
--SELECT DISTINCT sql = 'ALTER TABLE [' + tc2.TABLE_SCHEMA + '].[' + tc2.TABLE_NAME + '] DROP [' + rc1.CONSTRAINT_NAME + '];'
|
||||||
|
--FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc1
|
||||||
|
--LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc2 ON tc2.CONSTRAINT_NAME =rc1.CONSTRAINT_NAME
|
||||||
|
|
||||||
|
--OPEN @Cursor FETCH NEXT FROM @Cursor INTO @Sql
|
||||||
|
|
||||||
|
--WHILE (@@FETCH_STATUS = 0)
|
||||||
|
--BEGIN
|
||||||
|
--Exec sp_executesql @Sql
|
||||||
|
--FETCH NEXT FROM @Cursor INTO @Sql
|
||||||
|
--END
|
||||||
|
|
||||||
|
--CLOSE @Cursor DEALLOCATE @Cursor
|
||||||
|
--GO
|
||||||
|
|
||||||
|
--EXEC sp_MSforeachtable 'DROP TABLE ?'
|
||||||
|
--GO
|
||||||
|
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
CREATE TABLE [User] (
|
CREATE TABLE [User] (
|
||||||
ID INT IDENTITY(0, 1) NOT NULL,
|
ID INT IDENTITY(0, 1) NOT NULL,
|
||||||
Email VARCHAR(254) NOT NULL,
|
Email VARCHAR(254) NOT NULL,
|
||||||
|
@ -28,6 +57,8 @@ CREATE TABLE [Achievement] (
|
||||||
Thumbnail VARCHAR(256) NULL
|
Thumbnail VARCHAR(256) NULL
|
||||||
PRIMARY KEY(ID)
|
PRIMARY KEY(ID)
|
||||||
FOREIGN KEY(GameID) REFERENCES [Game](ID)
|
FOREIGN KEY(GameID) REFERENCES [Game](ID)
|
||||||
|
ON UPDATE CASCADE
|
||||||
|
ON DELETE CASCADE
|
||||||
)
|
)
|
||||||
|
|
||||||
CREATE TABLE [Owns] (
|
CREATE TABLE [Owns] (
|
||||||
|
@ -35,47 +66,69 @@ CREATE TABLE [Owns] (
|
||||||
GameID INT NOT NULL,
|
GameID INT NOT NULL,
|
||||||
PlatformID INT NOT NULL
|
PlatformID INT NOT NULL
|
||||||
PRIMARY KEY(UserID, GameID, PlatformID)
|
PRIMARY KEY(UserID, GameID, PlatformID)
|
||||||
FOREIGN KEY(UserID) REFERENCES [User](ID),
|
FOREIGN KEY(UserID) REFERENCES [User](ID)
|
||||||
FOREIGN KEY(GameID) REFERENCES [Game](ID),
|
ON UPDATE CASCADE
|
||||||
|
ON DELETE CASCADE,
|
||||||
|
FOREIGN KEY(GameID) REFERENCES [Game](ID)
|
||||||
|
ON UPDATE CASCADE
|
||||||
|
ON DELETE CASCADE,
|
||||||
FOREIGN KEY(PlatformID) REFERENCES [Platform](ID)
|
FOREIGN KEY(PlatformID) REFERENCES [Platform](ID)
|
||||||
|
ON UPDATE CASCADE
|
||||||
|
ON DELETE CASCADE
|
||||||
)
|
)
|
||||||
|
|
||||||
CREATE TABLE [Progress] (
|
CREATE TABLE [Progress] (
|
||||||
UserID INT NOT NULL,
|
UserID INT NOT NULL,
|
||||||
GameID INT NOT NULL,
|
PlatformID INT NOT NULL,
|
||||||
AchievementID INT NOT NULL,
|
AchievementID INT NOT NULL,
|
||||||
Progress INT NOT NULL
|
Progress INT NOT NULL
|
||||||
PRIMARY KEY(UserID, GameID, AchievementID)
|
PRIMARY KEY(UserID, AchievementID)
|
||||||
FOREIGN KEY(UserID) REFERENCES [User](ID),
|
FOREIGN KEY(UserID) REFERENCES [User](ID)
|
||||||
FOREIGN KEY(GameID) REFERENCES [Game](ID),
|
ON UPDATE CASCADE
|
||||||
|
ON DELETE CASCADE,
|
||||||
|
FOREIGN KEY(PlatformID) REFERENCES [Platform](ID)
|
||||||
|
ON UPDATE CASCADE
|
||||||
|
ON DELETE CASCADE,
|
||||||
FOREIGN KEY(AchievementID) REFERENCES [Achievement](ID)
|
FOREIGN KEY(AchievementID) REFERENCES [Achievement](ID)
|
||||||
|
ON UPDATE CASCADE
|
||||||
|
ON DELETE CASCADE
|
||||||
)
|
)
|
||||||
|
|
||||||
CREATE TABLE [IsOn] (
|
CREATE TABLE [IsOn] (
|
||||||
UserID INT NOT NULL,
|
UserID INT NOT NULL,
|
||||||
PlatformID INT NOT NULL
|
PlatformID INT NOT NULL
|
||||||
PRIMARY KEY(UserID, PlatformID)
|
PRIMARY KEY(UserID, PlatformID)
|
||||||
FOREIGN KEY(UserID) REFERENCES [User](ID),
|
FOREIGN KEY(UserID) REFERENCES [User](ID)
|
||||||
|
ON UPDATE CASCADE
|
||||||
|
ON DELETE CASCADE,
|
||||||
FOREIGN KEY(PlatformID) REFERENCES [Platform](ID)
|
FOREIGN KEY(PlatformID) REFERENCES [Platform](ID)
|
||||||
|
ON UPDATE CASCADE
|
||||||
|
ON DELETE CASCADE
|
||||||
)
|
)
|
||||||
|
|
||||||
CREATE TABLE [ExistsOn] (
|
CREATE TABLE [ExistsOn] (
|
||||||
GameID INT NOT NULL,
|
GameID INT NOT NULL,
|
||||||
PlatformID INT NOT NULL
|
PlatformID INT NOT NULL,
|
||||||
|
PlatformGameID INT NOT NULL
|
||||||
PRIMARY KEY(GameID, PlatformID)
|
PRIMARY KEY(GameID, PlatformID)
|
||||||
FOREIGN KEY(GameID) REFERENCES [Game](ID),
|
FOREIGN KEY(GameID) REFERENCES [Game](ID)
|
||||||
|
ON UPDATE CASCADE
|
||||||
|
ON DELETE CASCADE,
|
||||||
FOREIGN KEY(PlatformID) REFERENCES [Platform](ID)
|
FOREIGN KEY(PlatformID) REFERENCES [Platform](ID)
|
||||||
|
ON UPDATE CASCADE
|
||||||
)
|
)
|
||||||
|
|
||||||
CREATE TABLE [Rating] (
|
CREATE TABLE [Rating] (
|
||||||
UserID INT NOT NULL,
|
UserID INT NOT NULL,
|
||||||
GameID INT NOT NULL,
|
|
||||||
AchievementID INT NOT NULL,
|
AchievementID INT NOT NULL,
|
||||||
Quality FLOAT NULL,
|
Quality FLOAT NULL,
|
||||||
Difficulty FLOAT NULL,
|
Difficulty FLOAT NULL,
|
||||||
[Description] VARCHAR(1024) NULL
|
[Description] VARCHAR(1024) NULL
|
||||||
PRIMARY KEY(UserID, GameID, AchievementID)
|
PRIMARY KEY(UserID, AchievementID)
|
||||||
FOREIGN KEY(UserID) REFERENCES [User](ID),
|
FOREIGN KEY(UserID) REFERENCES [User](ID)
|
||||||
FOREIGN KEY(GameID) REFERENCES [Game](ID),
|
ON UPDATE CASCADE
|
||||||
|
ON DELETE CASCADE,
|
||||||
FOREIGN KEY(AchievementID) REFERENCES [Achievement](ID)
|
FOREIGN KEY(AchievementID) REFERENCES [Achievement](ID)
|
||||||
|
ON UPDATE CASCADE
|
||||||
|
ON DELETE CASCADE
|
||||||
)
|
)
|
||||||
|
|
BIN
sql/CreateUserSP.sql
Normal file
BIN
sql/CreateUserSP.sql
Normal file
Binary file not shown.
Loading…
Reference in a new issue