-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase.sql
More file actions
executable file
·134 lines (103 loc) · 3.43 KB
/
Copy pathDatabase.sql
File metadata and controls
executable file
·134 lines (103 loc) · 3.43 KB
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
IF EXISTS (SELECT name FROM sys.databases WHERE name = N'DrawGuesser')
DROP DATABASE [DrawGuesser]
GO
CREATE DATABASE DrawGuesser;
GO
use DrawGuesser;
create table _User
(UserID int Not Null primary key Identity(1,1),
Fname varchar(64) Not Null,
Lname varchar(64) Not Null,
userName varchar(64) not null unique,
_Password varchar(64) Not Null,
Email varchar(64) Not Null ,
_Level int Not Null,
_Exp int Not Null
);
create table Word_Category
(CategoryID int Not Null primary key Identity(1,1),
CatagoryName varchar(64) Not Null
);
create table Words(
WordID int Not Null primary key Identity(1,1),
CategoryID int Not Null,
WordName varchar(64) Not Null
foreign key(CategoryID) references Word_Category(CategoryID)
)
create table DifficultyLevel
(DifficultyLevel nvarchar(25) Not Null primary key,
TimePeriod int Not Null
);
create table Drawing
(DrawingID int Not Null primary key Identity(1,1),
WordID int Not Null,
DifficultyLevel nvarchar(25) Not Null,
UserID int Not Null,
DrawingData nvarchar(MAX),
foreign key (UserID) references _User(UserID),
foreign key (WordID) references Words(WordID) ,
foreign key (DifficultyLevel) references DifficultyLevel(DifficultyLevel)
);
Create table Guess
(GuessingID int Not Null primary key Identity(1,1),
DifficultyLevel nvarchar(25) Not Null,
DrawingID int Not Null,
UserID int Not Null,
SucceedTimes int Not Null,
TotalTime int Not Null,
foreign key (DifficultyLevel) references DifficultyLevel(DifficultyLevel),
foreign key (DrawingID) references Drawing(DrawingID) ,
foreign key (UserID) references _User(UserID)
);
-- Ensure that user with correct answer for specific image will never receive that image again
Create table Correct_Guess
(
UserID int not null ,
DrawingID int not null
constraint PK_UserID_DrawingID primary key (UserID,DrawingID),
constraint FK_UserID foreign key (UserID) references _User(UserID),
constraint FK_DrawingID foreign key (DrawingID) references Drawing(DrawingID)
)
insert into Word_Category (CatagoryName) values
('Fruit'),
('Animal'),
('Games');
insert into Words (CategoryID, WordName) values
( 1, 'Apple'),
( 1, 'Papaya'),
( 1, 'Banana'),
( 2, 'Cat'),
( 2, 'Dog'),
( 2, 'Fish'),
( 3, 'Mario'),
( 3, 'Luigi'),
( 3, 'Sanic');
insert into DifficultyLevel values
('Easy', 180),
('Intermediate', 120),
('Hard', 60);
Select WordID,Word_Category.CatagoryName,WordName From Words
JOIN Word_Category ON Word_Category.CategoryID = Words.CategoryID;
Select * from _User
Select * from Guess
select * from drawing
select * from Correct_Guess
insert into drawing(UserID,WordID,DifficultyLevel,DrawingData) select 1,1,'Easy', convert(varbinary(max),'asd')
delete from drawing
DBCC CHECKIDENT ('drawing', RESEED,0)
GO
SELECT sum(SucceedTimes) as ss , sum(TotalTime) as total
from Guess
where DrawingID =2
SELECT top 1 WordName, WordID
FROM Words join Word_Category on Words.CategoryID = Word_Category.CategoryID
-- WHERE CatagoryName = 'Fruit'
ORDER BY NEWID()
Select *
From Words
ORDER BY NEWID()
select (99/100),userName from _User
select * from guess
SELECT sum(SucceedTimes) as succeed , sum(TotalTime) as total
from Guess
where DrawingID = 3