0% found this document useful (0 votes)
11 views

Create Database and Tables

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Create Database and Tables

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Create Database:

CREATE DATABASE smart_waste_management;

USE smart_waste_management;

Create Users Table:


CREATE TABLE Users (

user_id INT AUTO_INCREMENT PRIMARY KEY,

name VARCHAR(255) NOT NULL,

email VARCHAR(255) NOT NULL UNIQUE,

password VARCHAR(255) NOT NULL,

location VARCHAR(255),

subscription_status TINYINT DEFAULT 0 -- 0 = inactive, 1 = active

);

Create Subscription Table:


CREATE TABLE Subscription (

subscription_id INT AUTO_INCREMENT PRIMARY KEY,

user_id INT,

start_date DATE,

end_date DATE,

amount DECIMAL(10, 2) NOT NULL,

status TINYINT DEFAULT 1, -- 0 = inactive, 1 = active

FOREIGN KEY (user_id) REFERENCES Users(user_id)

);

Create Waste_Types Table:


CREATE TABLE Waste_Types (

waste_type_id INT AUTO_INCREMENT PRIMARY KEY,

waste_name VARCHAR(255) NOT NULL,

description TEXT
);

Create Notifications Table:


CREATE TABLE Notifications (

notification_id INT AUTO_INCREMENT PRIMARY KEY,

user_id INT,

waste_type_id INT,

collection_date DATE,

sent TINYINT DEFAULT 0, -- 0 = not sent, 1 = sent

FOREIGN KEY (user_id) REFERENCES Users(user_id),

FOREIGN KEY (waste_type_id) REFERENCES Waste_Types(waste_type_id)

);

Create Leaderboard Table:


CREATE TABLE Leaderboard (

leaderboard_id INT AUTO_INCREMENT PRIMARY KEY,

user_id INT,

points INT DEFAULT 0,

rank INT DEFAULT 0,

FOREIGN KEY (user_id) REFERENCES Users(user_id)

);

Create Special_Pickups Table:


CREATE TABLE Special_Pickups (

request_id INT AUTO_INCREMENT PRIMARY KEY,

user_id INT,

item_description TEXT NOT NULL,

request_date DATE,

status TINYINT DEFAULT 0, -- 0 = pending, 1 = completed

FOREIGN KEY (user_id) REFERENCES Users(user_id)

);
Create Feedback Table:
CREATE TABLE Feedback (

feedback_id INT AUTO_INCREMENT PRIMARY KEY,

user_id INT,

feedback_text TEXT NOT NULL,

feedback_date DATE,

FOREIGN KEY (user_id) REFERENCES Users(user_id)

);

Sample Insert for Waste Types:


INSERT INTO Waste_Types (waste_name, description)

VALUES

('General Waste', 'Items that cannot be recycled or composted.'),

('Recycling', 'Paper, plastics, metals, and glass that can be recycled.'),

('Compost', 'Organic waste like food scraps, garden waste, etc.'),

('Hazardous Waste', 'Items like batteries, electronics, chemicals that require special disposal.');

You might also like