Question: Create an ER table and relationship of each entity. Entities and attributes are provided below. Users: user _ id , username, email, password _ hash,

Create an ER table and relationship of each entity. Entities and attributes are provided below.
Users:
user_id, username, email, password_hash, balance, registration_date, status, phone_number, date_of_birth
Events (Basketball Games):
event_id, event_name, event_date, home_team, away_team, league, venue, status, season
Teams:
team_id, team_name, abbreviation, city, arena, coach
Bets:
bet_id, user_id, event_id, bet_type, bet_amount, odds, bet_status, result, date_placed
Odds:
odds_id, event_id, bet_type, home_team_odds, away_team_odds, spread, over_under, odds_date, status
Transactions:
transaction_id, user_id, transaction_type, amount, transaction_date, balance_after, status
Betting History:
history_id, user_id, bet_id, event_id, bet_amount, odds_at_bet, result, date_placed, payout
Promotions:
promotion_id, promotion_name, promotion_type, description, start_date, end_date, minimum_bet, status.
SQL of the table are provided below.
-- Teams table
CREATE TABLE teams (
team_id SERIAL PRIMARY KEY,
team_name VARCHAR(100) NOT NULL,
city VARCHAR(100),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Games table
CREATE TABLE games (
game_id SERIAL PRIMARY KEY,
home_team_id INTEGER REFERENCES teams(team_id),
away_team_id INTEGER REFERENCES teams(team_id),
game_date TIMESTAMP NOT NULL,
home_team_score INTEGER,
away_team_score INTEGER,
status VARCHAR(20),-- Scheduled, Final
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Odds table
CREATE TABLE odds (
odds_id SERIAL PRIMARY KEY,
game_id INTEGER REFERENCES games(game_id),
bookmaker_id INTEGER REFERENCES bookmakers(bookmaker_id),
home_team_moneyline DECIMAL(10,2),
away_team_moneyline DECIMAL(10,2),
odds_timestamp TIMESTAMP NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Bookmakers table
CREATE TABLE bookmakers (
bookmaker_id SERIAL PRIMARY KEY,
bookmaker_name VARCHAR(100) NOT NULL,
status VARCHAR(20),-- Active, Inactive
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Users table
CREATE TABLE users (
user_id SERIAL PRIMARY KEY,
username VARCHAR(50) UNIQUE NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL,
password_hash VARCHAR(255) NOT NULL,
balance DECIMAL(10,2) DEFAULT 0,
status VARCHAR(20),-- Active, Suspended
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Bets table
CREATE TABLE bets (
bet_id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(user_id),
game_id INTEGER REFERENCES games(game_id),
odds_id INTEGER REFERENCES odds(odds_id),
bet_amount DECIMAL(10,2) NOT NULL,
odds_value DECIMAL(10,2) NOT NULL,
potential_payout DECIMAL(10,2) NOT NULL,
team_id INTEGER REFERENCES teams(team_id),-- The team bet on to win
status VARCHAR(20),-- Pending, Won, Lost
placed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
settled_at TIMESTAMP
);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!