0% found this document useful (0 votes)
4 views1 page

Create Table

The document outlines the creation of a database schema for an email management system, including tables for emails, users, spam senders, email logs, attachments, and folders. This structure allows for the storage and management of messages, user information, actions taken on emails, and custom folders. It is designed to be flexible and scalable to accommodate future needs.

Uploaded by

Iago Santarelli
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)
4 views1 page

Create Table

The document outlines the creation of a database schema for an email management system, including tables for emails, users, spam senders, email logs, attachments, and folders. This structure allows for the storage and management of messages, user information, actions taken on emails, and custom folders. It is designed to be flexible and scalable to accommodate future needs.

Uploaded by

Iago Santarelli
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/ 1

CREATE TABLE emails (

id INT AUTO_INCREMENT PRIMARY KEY,


sender_email VARCHAR(255) NOT NULL,
recipient_email VARCHAR(255) NOT NULL,
subject VARCHAR(255) NOT NULL,
body TEXT,
received_at DATETIME DEFAULT CURRENT_TIMESTAMP,
folder ENUM('inbox', 'spam', 'lixeira') DEFAULT 'inbox',
is_read BOOLEAN DEFAULT FALSE
);
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
name VARCHAR(100) NOT NULL,
password_hash VARCHAR(255) NOT NULL, -- Para armazenar a senha de forma segura
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE spam_senders (
id INT AUTO_INCREMENT PRIMARY KEY,
sender_email VARCHAR(255) UNIQUE NOT NULL,
marked_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE email_logs (
id INT AUTO_INCREMENT PRIMARY KEY,
email_id INT NOT NULL,
action ENUM('opened', 'deleted', 'marked_as_spam') NOT NULL,
action_timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (email_id) REFERENCES emails(id)
);
CREATE TABLE attachments (
id INT AUTO_INCREMENT PRIMARY KEY,
email_id INT NOT NULL,
filename VARCHAR(255) NOT NULL,
file_path VARCHAR(255) NOT NULL,
uploaded_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (email_id) REFERENCES emails(id)
);
CREATE TABLE folders (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
folder_name VARCHAR(100) NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id)
);

Essas tabelas são a base de um sistema de e-mails que permite armazenar e gerenciar
mensagens, usuários, as ações que foram feitas com os e-mails, anexos e até pastas
personalizadas. A estrutura é bem flexível e dá espaço para crescer conforme
necessidade.

You might also like