Changes between Initial Version and Version 1 of ddlScriptVer1.sql


Ignore:
Timestamp:
11/20/24 17:34:15 (3 days ago)
Author:
211101
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ddlScriptVer1.sql

    v1 v1  
     1
     2{{{#!sql
     3-- Create USER table
     4CREATE TABLE USER (
     5    user_id SERIAL PRIMARY KEY,
     6    user_name VARCHAR(50) NOT NULL,
     7    email VARCHAR(100) NOT NULL,
     8    password VARCHAR(100) NOT NULL
     9);
     10
     11-- Create TRANSACTION_ACCOUNT table
     12CREATE TABLE TRANSACTION_ACCOUNT (
     13    transaction_account_id SERIAL PRIMARY KEY,
     14    account_name VARCHAR(50),
     15    balance DECIMAL(10, 2),
     16    user_id INT REFERENCES USER(user_id)
     17);
     18
     19-- Create TRANSACTION table
     20CREATE TABLE TRANSACTION (
     21    transaction_id SERIAL PRIMARY KEY,
     22    transaction_name VARCHAR(100),
     23    amount DECIMAL(10, 2) NOT NULL,
     24    net_amount DECIMAL(10, 2),
     25    day_id INT REFERENCES DAY(day_id),
     26    tag_id INT REFERENCES TAG(tag_id)
     27);
     28
     29-- Create TRANSACTION_BREAKDOWN table
     30CREATE TABLE TRANSACTION_BREAKDOWN (
     31    transaction_breakdown_id SERIAL PRIMARY KEY,
     32    transaction_id INT REFERENCES TRANSACTION(transaction_id),
     33    transaction_account_id INT REFERENCES TRANSACTION_ACCOUNT(transaction_account_id),
     34    spent_amount DECIMAL(10, 2),
     35    earned_amount DECIMAL(10, 2)
     36);
     37
     38-- Create YEAR table
     39CREATE TABLE YEAR (
     40    year_id SERIAL PRIMARY KEY,
     41    year_name INT NOT NULL
     42);
     43
     44-- Create MONTH table
     45CREATE TABLE MONTH (
     46    month_id SERIAL PRIMARY KEY,
     47    year_id INT REFERENCES YEAR(year_id),
     48    month_name VARCHAR(20) NOT NULL
     49);
     50
     51-- Create DAY table
     52CREATE TABLE DAY (
     53    day_id SERIAL PRIMARY KEY,
     54    month_id INT REFERENCES MONTH(month_id),
     55    day_number INT,
     56    day_name VARCHAR(20)
     57);
     58
     59-- Create TAG table
     60CREATE TABLE TAG (
     61    tag_id SERIAL PRIMARY KEY,
     62    tag_name VARCHAR(50) NOT NULL
     63);
     64
     65-- Delete tables if they exist
     66DROP TABLE IF EXISTS TRANSACTION_BREAKDOWN CASCADE;
     67DROP TABLE IF EXISTS TRANSACTION CASCADE;
     68DROP TABLE IF EXISTS TRANSACTION_ACCOUNT CASCADE;
     69DROP TABLE IF EXISTS DAY CASCADE;
     70DROP TABLE IF EXISTS MONTH CASCADE;
     71DROP TABLE IF EXISTS YEAR CASCADE;
     72DROP TABLE IF EXISTS TAG CASCADE;
     73DROP TABLE IF EXISTS USER CASCADE;
     74}}}