Mark As Completed Discussion

Designing Database Schema

Once we have identified the entities and their relationships in our payment app, the next step is to design the database schema. The database schema represents the structure of the database and how the entities and their attributes are organized.

In our case, we can design the database schema using SQL. Let's take a look at an example schema:

TEXT/X-SQL
1CREATE TABLE User (
2  id INT PRIMARY KEY,
3  name VARCHAR(255),
4  email VARCHAR(255)
5);
6
7CREATE TABLE Address (
8  id INT PRIMARY KEY,
9  street VARCHAR(255),
10  city VARCHAR(255),
11  state VARCHAR(255),
12  zipCode VARCHAR(10)
13);
14
15CREATE TABLE PaymentMethod (
16  id INT PRIMARY KEY,
17  name VARCHAR(255),
18  type VARCHAR(255),
19  isActive BOOLEAN
20);
21
22CREATE TABLE Transaction (
23  id INT PRIMARY KEY,
24  user_id INT,
25  paymentMethod_id INT,
26  amount DOUBLE,
27  status BOOLEAN,
28  FOREIGN KEY (user_id) REFERENCES User(id),
29  FOREIGN KEY (paymentMethod_id) REFERENCES PaymentMethod(id)
30);
JAVA
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment