This document summarizes the database schema and how the application connects to and uses the database. The canonical schema is in Schema.sql.
- Database name:
Bank(seedb.get_connection()indb.py) - Access: Windows (trusted) authentication via ODBC Driver 17 for SQL Server
See db.py for the connection string used by the application.
- The app opens connections using
pyodbcand the helper functionget_connection()defined indb.py. - The connection string uses
DRIVER={ODBC Driver 17 for SQL Server},SERVER=localhost,DATABASE=Bank, andTrusted_Connection=yes.
Callers obtain a connection and must close it when finished; the
application's data.py helper functions (execute, fetch) wrap that
pattern for convenience.
Below are the tables defined in Schema.sql with the most important columns and notes about relationships.
DeptCodeNVARCHAR(50) PRIMARY KEY — business key for a departmentDescriptionNVARCHAR(500)ManagerIdINT NULL — optional FK toEmployee.EmpId(manager)
Notes: departments are referenced by Employee.DeptCode.
BranchIdINT IDENTITY PRIMARY KEY — surrogate integer idBranchCodeNVARCHAR(50)OpeningHoursNVARCHAR(100)EmailNVARCHAR(100)PhoneNVARCHAR(20)ManagerIdINT NULL — optional FK toEmployee.EmpId
Notes: branches are referenced by Employee.BranchId and Account.BranchId.
EmpIdINT IDENTITY PRIMARY KEYDeptCodeNVARCHAR(50) NOT NULL — FK ->Department(DeptCode)BranchIdINT NOT NULL — FK ->Branch(BranchId)ManagerIdINT NULL — FK ->Employee(EmpId)(self-relationship)HireDate,BirthDate,Email,Phone,Address,WorkHours
Notes: employees belong to a department and branch; there is a recursive manager relationship allowing hierarchical staff structures.
CustomerIdINT IDENTITY PRIMARY KEYSSNNVARCHAR(20) UNIQUE NOT NULL — unique identifier for customersGenderCHAR(1),RegDateDATE,IsActiveBITJob,IncomeLevel
Notes: customers are referenced by Account.CustomerId.
AccountIdINT IDENTITY PRIMARY KEYIBANNVARCHAR(50) UNIQUE NOT NULLCustomerIdINT NOT NULL — FK ->Customer(CustomerId)BranchIdINT NOT NULL — FK ->Branch(BranchId)Status,Currency,BalanceDECIMAL(18,2)LastTransactionDateDATETIME
Notes: balances use DECIMAL(18,2). Account operations in the app use
AccountId to reference accounts. Ensure IBAN uniqueness is kept.
TransactionIdINT IDENTITY PRIMARY KEYAccountIdINT NOT NULL — FK ->Account(AccountId)EmpIdINT NOT NULL — FK ->Employee(EmpId)AmountDECIMAL(18,2)StatusNVARCHAR(20)TransactionDateDATE,TransactionTimeTIME
Notes: the app inserts transactions using SQL Server's GETDATE() to
set the transaction timestamp. Keep in mind the table name is a SQL
keyword, hence the use of square brackets: [Transaction].
Employee.DeptCode->Department.DeptCodeEmployee.BranchId->Branch.BranchIdEmployee.ManagerId->Employee.EmpId(self-FK)Branch.ManagerId->Employee.EmpId(optional)Department.ManagerId->Employee.EmpId(optional)Account.CustomerId->Customer.CustomerIdAccount.BranchId->Branch.BranchIdTransaction.AccountId->Account.AccountIdTransaction.EmpId->Employee.EmpId
- Select all accounts with customer SSN and branch code:
SELECT a.AccountId, a.IBAN, c.SSN, b.BranchCode, a.Balance
FROM Account a
JOIN Customer c ON a.CustomerId = c.CustomerId
JOIN Branch b ON a.BranchId = b.BranchId;- Insert a transaction (application uses parameterized statements):
INSERT INTO [Transaction] (AccountId, EmpId, Amount, TransactionDate)
VALUES (?, ?, ?, GETDATE());- Update an account balance (do this inside a transaction in real apps):
UPDATE Account
SET Balance = Balance + ?
WHERE AccountId = ?;- Use parameterized queries from the application (the code uses
?placeholders withpyodbc) to protect against SQL injection. - Consider adding indexes on frequently queried columns such as
Customer.SSN,Account.IBAN,Transaction.TransactionDate. - When performing multi-step operations (e.g., creating a transaction and updating an account balance) use explicit DB transactions to ensure atomicity.
- The schema uses identity columns for numeric primary keys and NVARCHAR for textual keys; be consistent when joining and casting.
Seed data is available in SeedData.sql (if present) and can be used
to populate the database for development/testing.
- Connection helper:
db.py(get_connection()) - Simple data helpers:
data.py(execute,fetch) - GUI usage and example queries:
app.py— the UI code callsexecute()andfetch()for CRUD operations on these tables.