Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

for the following database execute the statements and show output (eg the tables with rows and columns) create logical and physical model digitally CREATE DATABASE

for the following database execute the statements and show output (eg the tables with rows and columns) create logical and physical model digitally

CREATE DATABASE bank;

USE bank;

CREATE TABLE accounts (

account_id INTEGER PRIMARY KEY,

account_type VARCHAR(255) NOT NULL,

account_balance DECIMAL(10,2) NOT NULL,

user_id INTEGER NOT NULL,

FOREIGN KEY (user_id) REFERENCES users(user_id)

);

CREATE TABLE users (

user_id INTEGER PRIMARY KEY,

first_name VARCHAR(255) NOT NULL,

last_name VARCHAR(255) NOT NULL,

email VARCHAR(255) NOT NULL UNIQUE,

password VARCHAR(255) NOT NULL

);

CREATE TABLE transactions (

transaction_id INTEGER PRIMARY KEY,

transaction_type VARCHAR(255) NOT NULL,

transaction_amount DECIMAL(10,2) NOT NULL,

account_id INTEGER NOT NULL,

FOREIGN KEY (account_id) REFERENCES accounts(account_id)

);

CREATE TABLE loans (

loan_id INTEGER PRIMARY KEY,

loan_type VARCHAR(255) NOT NULL,

loan_amount DECIMAL(10,2) NOT NULL,

account_id INTEGER NOT NULL,

FOREIGN KEY (account_id) REFERENCES accounts(account_id)

);

CREATE TABLE credit_cards (

credit_card_id INTEGER PRIMARY KEY,

credit_card_type VARCHAR(255) NOT NULL,

credit_card_number CHAR(16) NOT NULL UNIQUE,

expiration_date DATE NOT NULL,

user_id INTEGER NOT NULL,

FOREIGN KEY (user_id) RE REFERENCES users(user_id)

);

INSERT INTO accounts (account_id, account_type, account_balance, user_id) VALUES (1, 'checking', 100.00, 1), (2, 'savings', 1000.00, 2), (3, 'investment', 10000.00, 3);

INSERT INTO users (user_id, first_name, last_name, email, password) VALUES (1, 'John', 'Doe', 'johndoe@example.com', 'password123'), (2, 'Jane', 'Smith', 'janesmith@example.com', 'password456'), (3, 'Mary', 'Jones', 'maryjones@example.com', 'password789');

INSERT INTO transactions (transaction_id, transaction_type, transaction_amount, account_id) VALUES (1, 'deposit', 50.00, 1), (2, 'withdrawal', 25.00, 1), (3, 'deposit', 100.00, 2), (4, 'withdrawal', 50.00, 2),

(4, 'withdrawal', 100.00, 2),

(5, 'deposit', 2000.00, 3),

(6, 'withdrawal', 1000.00, 3);

INSERT INTO loans (loan_id, loan_type, loan_amount, account_id) VALUES (1, 'personal', 1000.00, 1), (2, 'student', 5000.00, 2), (3, 'car', 10000.00, 3);

INSERT INTO credit_cards (credit_card_id, credit_card_type, credit_card_number, expiration_date, user_id) VALUES (1, 'visa', '1234123412341234', '2022-12-31', 1), (2, 'visa', '2345234523452345', '2022-12-31', 2), (3, 'mastercard', '3456345634653465', '2022-12-31', 3);

ALTER TABLE accounts ADD CHECK (account_type IN ('checking', 'savings', 'investment')), ALTER TABLE credit_cards ADD UNIQUE (credit_card_number), ADD CHECK (expiration_date > CURRENT_DATE)

INSERT INTO accounts (account_id, account_type, account_balance, user_id) VALUES (1, 'checking', 100.00, 1) ON CONFLICT (account_id) DO UPDATE SET account_balance = accounts.account_balance + EXCLUDED.account_balance WHERE accounts.account_type = EXCLUDED.account_type;

COMMIT;

To conclude the code for the database, I have added a COMMIT statement to save the changes that I have made to the database.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions