· 7 years ago · Oct 05, 2018, 10:30 AM
1-- Created by Vertabelo (http://vertabelo.com)
2-- Last modification date: 2018-10-01 08:56:11.009
3
4-- tables
5-- Table: Images
6CREATE TABLE Images (
7 ImagesID int NOT NULL,
8 ImagePath varchar(255) NOT NULL,
9 Created date NOT NULL,
10 Updated date NOT NULL,
11 Deleted date NOT NULL,
12 CONSTRAINT Images_pk PRIMARY KEY (ImagesID)
13);
14
15-- Table: Properties
16CREATE TABLE Properties (
17 PropertiesID int NOT NULL,
18 Address1 varchar(255) NOT NULL,
19 Address2 varchar(255) NOT NULL,
20 Address3 varchar(255) NOT NULL,
21 Postcode varchar(7) NOT NULL,
22 Type varchar(20) NOT NULL,
23 Price numeric(13,2) NOT NULL,
24 Description text NOT NULL,
25 SaleStatus varchar(30) NOT NULL,
26 Created date NOT NULL,
27 Updated date NOT NULL,
28 Deleted date NOT NULL,
29 CONSTRAINT Properties_pk PRIMARY KEY (PropertiesID)
30);
31
32-- Table: PropertiesImages
33CREATE TABLE PropertiesImages (
34 PropertiesImagesID int NOT NULL,
35 ImagesID int NOT NULL,
36 PropertiesID int NOT NULL,
37 CONSTRAINT PropertiesImages_pk PRIMARY KEY (PropertiesImagesID)
38);
39
40-- Table: Users
41CREATE TABLE Users (
42 UsersID int NOT NULL AUTO_INCREMENT,
43 EmailAddress varchar(100) NOT NULL,
44 Fname varchar(255) NOT NULL,
45 Lname varchar(255) NOT NULL,
46 Password varchar(100) NOT NULL,
47 Created date NOT NULL,
48 `Update` date NOT NULL,
49 Deleted date NOT NULL,
50 RoleEntityKey int NOT NULL,
51 SecretKey varchar(255) NOT NULL,
52 CONSTRAINT Users_pk PRIMARY KEY (UsersID)
53);
54
55-- Table: UsersImages
56CREATE TABLE UsersImages (
57 UsersImagesID int NOT NULL,
58 UsersID int NOT NULL,
59 ImagesID int NOT NULL,
60 CONSTRAINT UsersImages_pk PRIMARY KEY (UsersImagesID)
61);
62
63-- Table: UsersProperties
64CREATE TABLE UsersProperties (
65 UsersPropertiesID int NOT NULL,
66 UsersID int NOT NULL,
67 PropertiesID int NOT NULL,
68 CONSTRAINT UsersProperties_pk PRIMARY KEY (UsersPropertiesID)
69);
70
71-- foreign keys
72-- Reference: PropertiesImages_Images (table: PropertiesImages)
73ALTER TABLE PropertiesImages ADD CONSTRAINT PropertiesImages_Images FOREIGN KEY PropertiesImages_Images (ImagesID)
74 REFERENCES Images (ImagesID);
75
76-- Reference: PropertiesImages_Properties (table: PropertiesImages)
77ALTER TABLE PropertiesImages ADD CONSTRAINT PropertiesImages_Properties FOREIGN KEY PropertiesImages_Properties (PropertiesID)
78 REFERENCES Properties (PropertiesID);
79
80-- Reference: UsersImages_Images (table: UsersImages)
81ALTER TABLE UsersImages ADD CONSTRAINT UsersImages_Images FOREIGN KEY UsersImages_Images (ImagesID)
82 REFERENCES Images (ImagesID);
83
84-- Reference: UsersImages_Users (table: UsersImages)
85ALTER TABLE UsersImages ADD CONSTRAINT UsersImages_Users FOREIGN KEY UsersImages_Users (UsersID)
86 REFERENCES Users (UsersID);
87
88-- Reference: UsersProperties_Properties (table: UsersProperties)
89ALTER TABLE UsersProperties ADD CONSTRAINT UsersProperties_Properties FOREIGN KEY UsersProperties_Properties (PropertiesID)
90 REFERENCES Properties (PropertiesID);
91
92-- Reference: UsersProperties_Users (table: UsersProperties)
93ALTER TABLE UsersProperties ADD CONSTRAINT UsersProperties_Users FOREIGN KEY UsersProperties_Users (UsersID)
94 REFERENCES Users (UsersID);
95
96-- End of file.