-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameStoreDB.sql
158 lines (137 loc) · 4.88 KB
/
GameStoreDB.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
--CREATE DATABASE GameStoreDB
--USE GameStoreDB
--DROP DATABASE GameStoreDB
CREATE TABLE UserTypes(
UserTypeID INT IDENTITY(1,1) PRIMARY KEY,
UserTypeName VARCHAR(30) NOT NULL,
);
CREATE TABLE Users(
UserID INT IDENTITY(1,1) PRIMARY KEY,
UserName VARCHAR(30) NOT NULL,
UserEmail VARCHAR(30) NOT NULL,
UserPassword VARCHAR(30) NOT NULL,
UserTypeID INT NOT NULL,
UserRegisterDate DATETIME DEFAULT GETDATE()
);
CREATE TABLE FriendUsers(
FriendUsersID INT IDENTITY(1,1) PRIMARY KEY,
UserID1 INT NOT NULL,
UserID2 INT NOT NULL,
FOREIGN KEY (UserID1) REFERENCES Users(UserID),
FOREIGN KEY (UserID2) REFERENCES Users(UserID),
UNIQUE (UserID1, UserID2)
);
CREATE TABLE Categories(
CategoryID INT IDENTITY(1,1) PRIMARY KEY,
CategoryName VARCHAR(30) NOT NULL,
);
CREATE TABLE Games(
UserID INT NOT NULL,
GameID INT IDENTITY(1,1) PRIMARY KEY,
GameName VARCHAR(30) NOT NULL,
GameDescription VARCHAR(300) NOT NULL,
GamePrice MONEY NOT NULL,
GameCategoryID INT NOT NULL,
GameReleaseDate DATE NOT NULL,
GameCoverImagePath VARCHAR(100) NOT NULL,
GameDeveloper VARCHAR(30) NOT NULL,
GamePublisher VARCHAR(30) NOT NULL,
FOREIGN KEY (GameCategoryID) REFERENCES Categories(CategoryID),
FOREIGN KEY (UserID) REFERENCES Users(UserID),
);
CREATE TABLE ContentImages(
ContentImageID INT IDENTITY(1,1) PRIMARY KEY,
GameID INT NOT NULL,
ContentImagePath VARCHAR(100) NOT NULL,
FOREIGN KEY (GameID) REFERENCES Games(GameID),
);
/*CREATE TABLE Developers(
DeveloperID INT IDENTITY(1,1) PRIMARY KEY,
DeveloperName VARCHAR(30) NOT NULL,
);
CREATE TABLE GameDevelopers(
GameID INT NOT NULL,
DeveloperID INT NOT NULL,
FOREIGN KEY (GameID) REFERENCES Games(GameID),
FOREIGN KEY (DeveloperID) REFERENCES Developers(DeveloperID),
PRIMARY KEY (GameID, DeveloperID)
);
CREATE TABLE Publisher(
PublisherID INT IDENTITY(1,1) PRIMARY KEY,
PublisherName VARCHAR(30) NOT NULL,
);
CREATE TABLE GamePublishers(
GameID INT NOT NULL,
PublisherID INT NOT NULL,
FOREIGN KEY (GameID) REFERENCES Games(GameID),
FOREIGN KEY (PublisherID) REFERENCES Publisher(PublisherID),
PRIMARY KEY (GameID, PublisherID)
);
*/
CREATE TABLE Tags(
TagID INT IDENTITY(1,1) PRIMARY KEY,
TagName VARCHAR(30) NOT NULL,
);
CREATE TABLE GameTags(
GameID INT NOT NULL,
TagID INT NOT NULL,
FOREIGN KEY (GameID) REFERENCES Games(GameID),
FOREIGN KEY (TagID) REFERENCES Tags(TagID),
PRIMARY KEY (GameID, TagID)
);
CREATE TABLE OSystems(
OSystemID INT IDENTITY(1,1) PRIMARY KEY,
OSystemName VARCHAR(30) NOT NULL,
);
CREATE TABLE GameOSystems(
GameOSystemsID INT IDENTITY(1,1) PRIMARY KEY,
GameID INT NOT NULL,
OSystemID INT NOT NULL,
FOREIGN KEY (GameID) REFERENCES Games(GameID),
FOREIGN KEY (OSystemID) REFERENCES OSystems(OSystemID),
UNIQUE (GameID, OSystemID)
);
CREATE TABLE Comments(
CommentID INT IDENTITY(1,1) PRIMARY KEY,
CommentText VARCHAR(300) NOT NULL,
CommentDate DATETIME DEFAULT GETDATE(),
UserID INT NOT NULL,
GameID INT NOT NULL,
FOREIGN KEY (UserID) REFERENCES Users(UserID),
FOREIGN KEY (GameID) REFERENCES Games(GameID),
);
CREATE TABLE UserGames(
UserGameID INT IDENTITY(1,1) PRIMARY KEY,
UserID INT NOT NULL,
GameID INT NOT NULL,
FOREIGN KEY (UserID) REFERENCES Users(UserID),
FOREIGN KEY (GameID) REFERENCES Games(GameID),
UNIQUE (UserID, GameID)
);
INSERT INTO Categories(CategoryName) VALUES ('Action');
INSERT INTO Categories(CategoryName) VALUES ('Adventure');
INSERT INTO Categories(CategoryName) VALUES ('RPG');
INSERT INTO Categories(CategoryName) VALUES ('Simulation');
INSERT INTO Categories(CategoryName) VALUES ('Strategy');
INSERT INTO Categories(CategoryName) VALUES ('Sports');
INSERT INTO Categories(CategoryName) VALUES ('Racing');
INSERT INTO Categories(CategoryName) VALUES ('Fighting');
INSERT INTO Categories(CategoryName) VALUES ('Puzzle');
INSERT INTO Categories(CategoryName) VALUES ('Shooter');
INSERT INTO Categories(CategoryName) VALUES ('Horror');
INSERT INTO Categories(CategoryName) VALUES ('Platformer');
INSERT INTO Categories(CategoryName) VALUES ('MMO');
INSERT INTO Categories(CategoryName) VALUES ('Casual');
INSERT INTO Categories(CategoryName) VALUES ('Indie');
INSERT INTO Categories(CategoryName) VALUES ('Roleplay');
INSERT INTO Categories(CategoryName) VALUES ('Space & Flight');
INSERT INTO Categories(CategoryName) VALUES ('Card & Board');
INSERT INTO Categories(CategoryName) VALUES ('Building & Automation');
INSERT INTO UserTypes(UserTypeName) VALUES ('Admin');
INSERT INTO UserTypes(UserTypeName) VALUES ('User');
INSERT INTO Users(UserName, UserEmail, UserPassword, UserTypeID) VALUES ('Admin', '[email protected]', '123',1);
INSERT INTO Users(UserName, UserEmail, UserPassword, UserTypeID) VALUES ('Emir', '[email protected]', '123', 2);
INSERT INTO Users(UserName, UserEmail, UserPassword, UserTypeID) VALUES ('Emir2', '[email protected]', '123', 2);
INSERT INTO OSystems(OSystemName) VALUES ('Windows');
INSERT INTO OSystems(OSystemName) VALUES ('Linux');
INSERT INTO OSystems(OSystemName) VALUES ('Mac');