0% found this document useful (0 votes)
20 views3 pages

Database

Uploaded by

zintepest
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views3 pages

Database

Uploaded by

zintepest
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

DROP TABLE Profiles;

DROP TABLE Accounts;

CREATE TABLE Profiles (


name VARCHAR(20) PRIMARY KEY,
description TEXT NOT NULL,
status VARCHAR(20) NOT NULL
);

-- Inserting Admin profile


INSERT INTO Profiles (name, description, status)
VALUES ('Admin', 'Admin manages the website for properties and houses', 'active');

-- Inserting Seller profile


INSERT INTO Profiles (name, description, status)
VALUES ('Seller', 'Seller his listed properties for sale on the website',
'active');

-- Inserting Buyer profile


INSERT INTO Profiles (name, description, status)
VALUES ('Buyer', 'Buyer searches and purchases properties listed on the website',
'active');

-- Inserting Agent profile


INSERT INTO Profiles (name, description, status)
VALUES ('Agent', 'Agent assists in property transactions and listings on the
website', 'active');

CREATE TABLE Accounts (


username VARCHAR(50) NOT NULL,
password VARCHAR(50) NOT NULL,
name VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL,
phone_number VARCHAR(20),
agency_name VARCHAR(100),
license_number VARCHAR(50),
profile VARCHAR(20) NOT NULL,
status VARCHAR(20) NOT NULL,
PRIMARY KEY (username, profile),
CONSTRAINT fk_profile
FOREIGN KEY (profile)
REFERENCES Profiles(name)
);

-- Inserting admin user


INSERT INTO Accounts (username, password, name, email, profile, status)
VALUES ('admin', 'admin123', 'Admin Name', '[email protected]', 'Admin', 'active');

-- Inserting buyer user


INSERT INTO Accounts (username, password, name, email, phone_number, profile,
status)
VALUES ('buyer', 'buyer123', 'Buyer Name', '[email protected]', '1234567890',
'Buyer', 'active');

-- Inserting seller user


INSERT INTO Accounts (username, password, name, email, phone_number, profile,
status)
VALUES ('seller', 'seller123', 'Seller Name', '[email protected]', '9876543210',
'Seller', 'active');

-- Inserting agent user


INSERT INTO Accounts (username, password, name, email, phone_number, agency_name,
license_number, profile, status)
VALUES ('agent', 'agent123', 'Agent Name', '[email protected]', '5551234567', 'ABC
Realty', 'XYZ123', 'Agent', 'active');

CREATE TABLE propertyListings (


id INT NOT NULL AUTO_INCREMENT,
location VARCHAR(50) NOT NULL,
room INT NOT NULL,
propertyType VARCHAR(50) NOT NULL,
propertyCondition VARCHAR(50) NOT NULL,
price DECIMAL(10, 2) NOT NULL,
username1 VARCHAR(50) NOT NULL,
profile1 VARCHAR(20) NOT NULL,
username2 VARCHAR(50) NOT NULL,
profile2 VARCHAR(20) NOT NULL,
status VARCHAR(50) NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (username1) REFERENCES Accounts(username),
FOREIGN KEY (profile1) REFERENCES Accounts(profile),
FOREIGN KEY (username2) REFERENCES Accounts(username),
FOREIGN KEY (profile2) REFERENCES Accounts(profile)
);

INSERT INTO propertyListings (location, room, propertyType, propertyCondition,


price, username1, profile1, username2,profile2,status)
VALUES ('bukit', '2', 'HDB', 'new', '1000000', 'agent', 'Agent',
'seller','Seller','unsold');

INSERT INTO propertyListings (location, room, propertyType, propertyCondition,


price, username1, profile1, username2,profile2,status)
VALUES ('CityHall', '3', 'HDB', 'old', '1200000', 'agent', 'Agent',
'seller','Seller','unsold');

INSERT INTO propertyListings (location, room, propertyType, propertyCondition,


price, username1, profile1, username2,profile2,status)
VALUES ('Orchard', '4', 'condo', 'new', '2000000', 'agent', 'Agent',
'seller','Seller','unsold');

INSERT INTO propertyListings (location, room, propertyType, propertyCondition,


price, username1, profile1, username2,profile2,status)
VALUES ('bukit panjang', '5', 'landed', 'old', '2400000', 'agent', 'Agent',
'seller','Seller','unsold');

INSERT INTO propertyListings (location, room, propertyType, propertyCondition,


price, username1, profile1, username2,profile2,status)
VALUES ('clementi', '5', 'landed', 'new', '2800000', 'agent', 'Agent',
'seller','Seller','unsold');

CREATE TABLE buyList (


username VARCHAR(50) NOT NULL,
profile VARCHAR(20) NOT NULL,
id INT NOT NULL,
PRIMARY KEY (username, profile, id),
FOREIGN KEY (username) REFERENCES Accounts(username),
FOREIGN KEY (profile) REFERENCES Accounts(profile),
FOREIGN KEY (id) REFERENCES propertyListings(id)
);

insert into buyList(username,profile,id)


values ('buyer','Buyer','1');

insert into buyList(username,profile,id)


values ('buyer','Buyer','2');

CREATE TABLE review (


id INT AUTO_INCREMENT PRIMARY KEY,
star INT NOT NULL,
review TEXT NOT NULL,
username1 VARCHAR(50) NOT NULL,
profile1 VARCHAR(20) NOT NULL,
username2 VARCHAR(50) NOT NULL,
profile2 VARCHAR(20) NOT NULL,
FOREIGN KEY (username1) REFERENCES Accounts(username),
FOREIGN KEY (profile1) REFERENCES Accounts(profile),
FOREIGN KEY (username2) REFERENCES Accounts(username),
FOREIGN KEY (profile2) REFERENCES Accounts(profile)
);

You might also like