· 6 years ago · Jan 11, 2020, 09:58 PM
1if object_id('dbo.VideoGame', 'U') is not null
2 drop table dbo.VideoGame;
3if object_id('dbo.Genre', 'U') is not null
4 drop table dbo.Genre;
5if object_id('dbo.Company', 'U') is not null
6 drop table dbo.Company;
7if object_id('dbo.Platform', 'U') is not null
8 drop table dbo.Platform;
9if object_id('dbo.Developer', 'U') is not null
10 drop table dbo.Developer;
11if object_id('dbo.Date', 'U') is not null
12 drop table dbo.Date;
13
14if not exists (select * from sys.tables where name = 'Company')
15create table Company(
16 id_company int not null,
17 company nvarchar(255),
18 constraint PK_Company primary key (id_company)
19);
20
21if not exists (select * from sys.tables where name = 'Genre')
22create table Genre(
23 id_genre int not null,
24 genre nvarchar,
25 constraint PK_Genre primary key (id_genre)
26);
27
28if not exists (select * from sys.tables where name = 'Platform')
29create table Platform(
30 id_platform int not null,
31 platform nvarchar not null,
32 constraint PK_Platform primary key (id_platform)
33);
34
35if not exists (select * from sys.tables where name = 'Developer')
36create table Developer(
37 id_developer int not null,
38 developer varchar not null,
39 constraint PK_Developer primary key (id_developer)
40);
41
42if not exists (select * from sys.tables where name = 'Date')
43create table Date(
44 id_date int not null,
45 year int not null,
46 month int not null,
47 month_name nvarchar not null,
48 day int not null,
49 weekday nvarchar not null,
50 constraint PK_Date primary key (id_date)
51);
52
53create table VideoGame(
54 id_video_game int not null,
55 name nvarchar(255),
56 price money,
57 rating int,
58 id_platform int,
59 id_company int,
60 id_date int,
61 id_developer int,
62 id_genre int,
63 constraint PK_VideoGame primary key (id_video_game),
64 constraint FK_VideoGame_Platform foreign key (id_platform) references Platform (id_platform),
65 constraint FK_VideoGame_Company foreign key (id_company) references Company (id_company),
66 constraint FK_VideoGame_Date foreign key (id_date) references Date (id_date),
67 constraint FK_VideoGame_Developer foreign key (id_developer) references Developer (id_developer),
68 constraint FK_VideoGame_Genre foreign key (id_genre) references Genre (id_genre)
69);