aboutsummaryrefslogtreecommitdiff
blob: 5ca9c02a25f3918ce82cd226ed7a8155f1302242 (plain)
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
CREATE TABLE [dbo].[Apartment] (
    [ApartmentId]   INT           NOT NULL,
    [Size]          FLOAT (53)    NULL,
    [NumberOfRooms] INT           NULL,
    [MonthlyCharge] FLOAT (53)    NULL,
    [Floor]         INT           NULL,
    [Address]       VARCHAR (100) NULL,
    [PlanPicture]   VARCHAR (MAX) NULL,
    PRIMARY KEY CLUSTERED ([ApartmentId] ASC)
);

CREATE TABLE [dbo].[Change] (
    [ChangeId]    INT           IDENTITY (0, 1) NOT NULL,
    [ApartmentId] INT           NOT NULL,
    [Name]        VARCHAR (50)  NULL,
    [UploadDate]  DATE          NULL,
    [Description] VARCHAR (MAX) NULL,
    [Status]      VARCHAR (50)  NULL,
    PRIMARY KEY CLUSTERED ([ChangeId] ASC),
    CONSTRAINT [FK_Change_ToApartment] FOREIGN KEY ([ApartmentId]) REFERENCES [dbo].[Apartment] ([ApartmentId])
);

CREATE TABLE [dbo].[ChangeComment] (
    [CommentId] INT           IDENTITY (0, 1) NOT NULL,
    [ChangeId]  INT           NOT NULL,
    [Comment]   VARCHAR (MAX) NULL,
    [Name]      VARCHAR (50)  NULL,
    [Date]      DATETIME      NULL,
    PRIMARY KEY CLUSTERED ([CommentId] ASC),
    CONSTRAINT [FK_ChangeComment_ToChange] FOREIGN KEY ([ChangeId]) REFERENCES [dbo].[Change] ([ChangeId]) ON DELETE CASCADE
);

CREATE TABLE [dbo].[ChangeDocument] (
    [DocumentId] INT          IDENTITY (0, 1) NOT NULL,
    [ChangeId]   INT          NOT NULL,
    [Document]   VARCHAR (50) NULL,
    PRIMARY KEY CLUSTERED ([DocumentId] ASC),
    CONSTRAINT [FK_ChangeDocument_ToChange] FOREIGN KEY ([ChangeId]) REFERENCES [dbo].[Change] ([ChangeId]) ON DELETE CASCADE
);

CREATE TABLE [dbo].[Defect] (
    [DefectId]    INT           IDENTITY (0, 1) NOT NULL,
    [ApartmentId] INT           NOT NULL,
    [Name]        VARCHAR (50)  NULL,
    [UploadDate]  DATE          NULL,
    [Description] VARCHAR (MAX) NULL,
    [Status]      VARCHAR (50)  NULL,
    PRIMARY KEY CLUSTERED ([DefectId] ASC),
    CONSTRAINT [FK_Defect_ToApartment] FOREIGN KEY ([ApartmentId]) REFERENCES [dbo].[Apartment] ([ApartmentId])
);

CREATE TABLE [dbo].[DefectComment] (
    [CommentId] INT           IDENTITY (0, 1) NOT NULL,
    [DefectId]  INT           NOT NULL,
    [Comment]   VARCHAR (MAX) NULL,
    [Name]      VARCHAR (50)  NULL,
    [Date]      DATETIME      NULL,
    PRIMARY KEY CLUSTERED ([CommentId] ASC),
    CONSTRAINT [FK_DefectComment_ToDefect] FOREIGN KEY ([DefectId]) REFERENCES [dbo].[Defect] ([DefectId]) ON DELETE CASCADE
);

CREATE TABLE [dbo].[DefectPicture] (
    [PictureId] INT           IDENTITY (0, 1) NOT NULL,
    [DefectId]  INT           NOT NULL,
    [Picture]   VARCHAR (MAX) NULL,
    PRIMARY KEY CLUSTERED ([PictureId] ASC),
    CONSTRAINT [FK_DefectPicture_ToDefect] FOREIGN KEY ([DefectId]) REFERENCES [dbo].[Defect] ([DefectId]) ON DELETE CASCADE
);

CREATE TABLE [dbo].[PastUser] (
    [Username]    VARCHAR (30) NOT NULL,
    [ApartmentId] INT          NOT NULL,
    [Password]    VARCHAR (30) NOT NULL,
    [IsBm]        BIT          NOT NULL,
    [FirstName]   VARCHAR (30) NULL,
    [LastName]    VARCHAR (30) NULL,
    [BirthDate]   DATE         NULL,
    [Phone]       VARCHAR (20) NULL,
    [Email]       VARCHAR (50) NULL,
    [Picture]     VARCHAR (50) NULL,
    [MoveInDate]  DATE         NULL,
    [MoveOutDate] DATE         NULL,
    PRIMARY KEY CLUSTERED ([Username] ASC),
    CONSTRAINT [FK_PastUser_ToApartment] FOREIGN KEY ([ApartmentId]) REFERENCES [dbo].[Apartment] ([ApartmentId])
);

CREATE TABLE [dbo].[Resident] (
    [ResidentId]  INT           IDENTITY (0, 1) NOT NULL,
    [ApartmentId] INT           NOT NULL,
    [FirstName]   VARCHAR (30)  NULL,
    [LastName]    VARCHAR (30)  NULL,
    [BirthDate]   DATE          NULL,
    [Phone]       VARCHAR (20)  NULL,
    [Email]       VARCHAR (50)  NULL,
    [Picture]     VARCHAR (MAX) NULL,
    PRIMARY KEY CLUSTERED ([ResidentId] ASC),
    CONSTRAINT [FK_Resident_ToApartment] FOREIGN KEY ([ApartmentId]) REFERENCES [dbo].[Apartment] ([ApartmentId])
);

CREATE TABLE [dbo].[User] (
    [Username]    VARCHAR (30)  NOT NULL,
    [ApartmentId] INT           NOT NULL,
    [Password]    VARCHAR (30)  NOT NULL,
    [IsBm]        BIT           NOT NULL,
    [FirstName]   VARCHAR (30)  NULL,
    [LastName]    VARCHAR (30)  NULL,
    [BirthDate]   DATE          NULL,
    [Phone]       VARCHAR (20)  NULL,
    [Email]       VARCHAR (50)  NULL,
    [Picture]     VARCHAR (MAX) NULL,
    [MoveInDate]  DATE          NULL,
    [MoveOutDate] DATE          NULL,
    PRIMARY KEY CLUSTERED ([Username] ASC),
    CONSTRAINT [FK_User_ToApartment] FOREIGN KEY ([ApartmentId]) REFERENCES [dbo].[Apartment] ([ApartmentId])
);