wiki:ddlScriptVer1.sql

Version 2 (modified by 211101, 3 days ago) ( diff )

--

-- Delete tables if they exist
DROP TABLE IF EXISTS TRANSACTION_BREAKDOWN CASCADE;
DROP TABLE IF EXISTS TRANSACTION CASCADE;
DROP TABLE IF EXISTS TRANSACTION_ACCOUNT CASCADE;
DROP TABLE IF EXISTS TAG CASCADE;
DROP TABLE IF EXISTS USER CASCADE;

-- Create USER table
CREATE TABLE USER (
    user_id SERIAL PRIMARY KEY,
    user_name VARCHAR(50) NOT NULL,
    email VARCHAR(100) NOT NULL,
    password VARCHAR(100) NOT NULL
);

-- Create TRANSACTION_ACCOUNT table
CREATE TABLE TRANSACTION_ACCOUNT (
    transaction_account_id SERIAL PRIMARY KEY,
    account_name VARCHAR(50),
    balance DECIMAL(10, 2),
    user_id INT REFERENCES USER(user_id)
);

-- Create TRANSACTION table
CREATE TABLE TRANSACTION (
    transaction_id SERIAL PRIMARY KEY,
    transaction_name VARCHAR(100),
    amount DECIMAL(10, 2) NOT NULL,
    net_amount DECIMAL(10, 2),
    date TIMESTAMPZ,
    tag_id INT REFERENCES TAG(tag_id)
);

-- Create TRANSACTION_BREAKDOWN table
CREATE TABLE TRANSACTION_BREAKDOWN (
    transaction_breakdown_id SERIAL PRIMARY KEY,
    transaction_id INT REFERENCES TRANSACTION(transaction_id),
    transaction_account_id INT REFERENCES TRANSACTION_ACCOUNT(transaction_account_id),
    spent_amount DECIMAL(10, 2),
    earned_amount DECIMAL(10, 2)
);

-- Create TAG table
CREATE TABLE TAG (
    tag_id SERIAL PRIMARY KEY,
    tag_name VARCHAR(50) NOT NULL
);
Note: See TracWiki for help on using the wiki.