Changes between Initial Version and Version 1 of ddlScript.sql


Ignore:
Timestamp:
12/08/24 22:18:59 (5 weeks ago)
Author:
211101
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ddlScript.sql

    v1 v1  
     1
     2{{{#!sql
     3-- Delete tables if they exist
     4DROP TABLE IF EXISTS transaction_breakdown CASCADE;
     5DROP TABLE IF EXISTS transaction CASCADE;
     6DROP TABLE IF EXISTS transaction_account CASCADE;
     7DROP TABLE IF EXISTS tag CASCADE;
     8DROP TABLE IF EXISTS "user" CASCADE;
     9
     10-- Create USER table
     11CREATE TABLE "user" (
     12    user_id SERIAL PRIMARY KEY,
     13    user_name VARCHAR(50) NOT NULL,
     14    email VARCHAR(100) NOT NULL,
     15    password VARCHAR(100) NOT NULL
     16);
     17
     18-- Create TRANSACTION_ACCOUNT table
     19CREATE TABLE transaction_account (
     20    transaction_account_id SERIAL PRIMARY KEY,
     21    account_name VARCHAR(50),
     22    balance DECIMAL(10, 2),
     23    user_id INT REFERENCES "user"(user_id)
     24);
     25
     26-- Create TAG table
     27CREATE TABLE tag (
     28    tag_id SERIAL PRIMARY KEY,
     29    tag_name VARCHAR(50) NOT NULL
     30);
     31
     32-- Create TRANSACTION table
     33CREATE TABLE transaction (
     34    transaction_id SERIAL PRIMARY KEY,
     35    transaction_name VARCHAR(100),
     36    amount DECIMAL(10, 2) NOT NULL,
     37    net_amount DECIMAL(10, 2),
     38    date TIMESTAMPTZ,
     39    tag_id INT REFERENCES tag(tag_id)
     40);
     41
     42-- Create TRANSACTION_BREAKDOWN table
     43CREATE TABLE transaction_breakdown (
     44    transaction_breakdown_id SERIAL PRIMARY KEY,
     45    transaction_id INT REFERENCES transaction(transaction_id),
     46    transaction_account_id INT REFERENCES transaction_account(transaction_account_id),
     47    spent_amount DECIMAL(10, 2),
     48    earned_amount DECIMAL(10, 2)
     49);
     50}}}