generated from Web-Development-Environments-2021/Assignment-3-2-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql_script.sql
81 lines (70 loc) · 2.52 KB
/
sql_script.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
EXEC sp_rename '[dbo].[favoriteGames].games', 'game_id', 'COLUMN';
CREATE TABLE [dbo].[users](
[user_id] [int] IDENTITY(1,1) NOT NULL,
[username] [varchar](30) NOT NULL UNIQUE,
[password] [varchar](300) NOT NULL
)
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[users]') AND type in (N'U'))
DROP TABLE [dbo].[users]
GO
CREATE TABLE [dbo].[users](
[user_id] [int] PRIMARY KEY NOT NULL,
[username] [varchar](30) NOT NULL,
[password] [varchar](300) NOT NULL,
[permissions] [varchar](30) NULL,
[first_name] [varchar](40) NULL,
[last_name] [varchar](40) NULL,
[country] [varchar](40) NULL,
[email] [varchar](40) NULL,
[image_user] [image] NULL
)
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[events_schedule]') AND type in (N'U'))
DROP TABLE [dbo].[events_schedule]
GO
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[refree_games]') AND type in (N'U'))
DROP TABLE [dbo].[refree_games]
GO
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[favoriteGames]') AND type in (N'U'))
DROP TABLE [dbo].[favoriteGames]
GO
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[games]') AND type in (N'U'))
DROP TABLE [dbo].[games]
GO
CREATE TABLE [dbo].[games](
[id] [bigint] NOT NULL PRIMARY KEY,
[date] [smalldatetime] NOT NULL,
[league_name] [varchar](300) NOT NULL,
[home_team_name] [varchar](30) NOT NULL,
[away_team_name] [varchar](30) NOT NULL,
[home_score] [int] NOT NULL,
[away_score] [int] NOT NULL,
[field] [varchar] (30) NOT NULL,
[winner] [varchar] (30) NULL,
);
CREATE TABLE [dbo].[events_schedule](
[events_scheduleID] [bigint] PRIMARY KEY NOT NULL,
[date] [smalldatetime] NOT NULL,
[minute] [int] NOT NULL,
[extra_minute] [int] NULL,
[player_id] [int] NOT NULL,
[player_name] [varchar](40) NOT NULL,
[type] [varchar](30) NOT NULL
);
CREATE TABLE [dbo].[refree_games](
[referee_id] [int] NOT NULL FOREIGN KEY REFERENCES dbo.refree(user_id),
[game_id][bigint] NOT NULL FOREIGN KEY REFERENCES dbo.games(id),
PRIMARY KEY(referee_id,game_id),
);
CREATE TABLE [dbo].[favoriteGames](
[user_id] [int] NOT NULL,
[game_id] [bigint] NOT NULL
);
-- CREATE TABLE [dbo].[refree](
-- [user_id] [int] NOT NULL PRIMARY KEY FOREIGN KEY REFERENCES dbo.users(user_id),
-- [qualification][VARCHAR](30),
-- );
select user_id from dbo.users WHERE first_name LIKE 'roi';
DELETE from dbo.users WHERE user_id=1 or user_id = 1;
UPDATE dbo.users
SET permissions = 'representative'
WHERE user_id = 0;