Banking System Queries - SQL Typing CST Test
Loading…
Banking System Queries — SQL Code
Demonstrates customer accounts, transactions, and account summaries.
CREATE TABLE customers (
customer_id SERIAL PRIMARY KEY,
customer_name VARCHAR(100),
email VARCHAR(100)
);
CREATE TABLE bank_accounts (
account_id SERIAL PRIMARY KEY,
customer_id INTEGER REFERENCES customers(customer_id),
balance DECIMAL(12,2)
);
INSERT INTO customers (customer_name, email) VALUES
('John Doe', 'john@example.com'),
('Emma Wilson', 'emma@example.com');
INSERT INTO bank_accounts (
customer_id,
balance
) VALUES
(1, 10000),
(2, 7500);
SELECT
c.customer_name,
b.account_id,
b.balance
FROM customers c
JOIN bank_accounts b
ON c.customer_id = b.customer_id;
SELECT
AVG(balance) AS average_balance,
MAX(balance) AS highest_balance,
MIN(balance) AS lowest_balance
FROM bank_accounts;SQL Language Guide
SQL (Structured Query Language) is a standard language for managing and manipulating relational databases, enabling querying, insertion, updating, and deletion of data efficiently.
Primary Use Cases
- ▸Querying relational data for applications
- ▸Data aggregation and reporting
- ▸Transaction management in business systems
- ▸Analytics and business intelligence
- ▸Database schema definition and data integrity enforcement
Notable Features
- ▸Declarative syntax for querying data
- ▸Support for CRUD operations: Create, Read, Update, Delete
- ▸Joins and subqueries for combining data
- ▸Transactions to ensure atomicity and consistency
- ▸Data definition language (DDL) for schema management
Origin & Creator
Developed at IBM in the early 1970s by Donald D. Chamberlin and Raymond F. Boyce.
Industrial Note
SQL is ubiquitous in enterprise, analytics, web applications, and data-intensive domains where structured relational data is used.
Quick Explain
- ▸SQL provides declarative commands to interact with relational database systems (RDBMS).
- ▸Supports querying, filtering, aggregation, joins, and transactions.
- ▸Used across major RDBMS like MySQL, PostgreSQL, Oracle, SQL Server, and SQLite.
- ▸Enforces schema, data types, constraints, and relationships.
- ▸Enables both simple queries and complex analytical operations.
Core Features
- ▸SELECT queries with filtering and ordering
- ▸INSERT, UPDATE, DELETE operations
- ▸JOINs (INNER, LEFT, RIGHT, FULL) and subqueries
- ▸GROUP BY, HAVING, and aggregate functions
- ▸Transactions and constraint enforcement
Learning Path
- ▸Understand relational data modeling
- ▸Learn basic CRUD operations
- ▸Master joins, subqueries, and aggregation
- ▸Study indexing, constraints, and transactions
- ▸Practice database optimization and analytics queries
Practical Examples
- ▸SELECT data with WHERE filters
- ▸JOIN multiple tables for relational queries
- ▸Aggregate data using SUM, COUNT, AVG, MAX, MIN
- ▸Create and manage tables with constraints
- ▸Use transactions to ensure atomic operations
Comparisons
- ▸SQL vs NoSQL: SQL for structured data, NoSQL for flexible schema/unstructured data
- ▸MySQL vs PostgreSQL: MySQL widely used, PostgreSQL more advanced features
- ▸SQL vs GraphQL: SQL queries relational data, GraphQL queries API endpoints
- ▸SQL vs ORM query languages: SQL native and powerful, ORM abstracts complexity
- ▸SQL vs Excel: SQL handles large datasets efficiently, Excel for small-scale analysis
Strengths
- ▸Standardized and widely supported across RDBMS
- ▸Powerful for structured data manipulation
- ▸Enables complex queries and analytics
- ▸ACID-compliant transactions ensure data reliability
- ▸Strong community and documentation support
Limitations
- ▸Less flexible for unstructured or hierarchical data
- ▸Complex queries can be hard to optimize
- ▸Performance depends on indexing and schema design
- ▸Portability issues with vendor-specific SQL extensions
- ▸Limited in handling very large-scale distributed data compared to NoSQL
When NOT to Use
- ▸For unstructured or schema-less data (use NoSQL)
- ▸When horizontal scaling of huge datasets is primary concern
- ▸Rapid prototyping of small, transient datasets
- ▸Applications requiring real-time streaming analytics only
- ▸When fully distributed databases are preferred
Cheat Sheet
- ▸SELECT * FROM table WHERE condition - basic query
- ▸INSERT INTO table (columns) VALUES (values) - add data
- ▸UPDATE table SET column=value WHERE condition - modify data
- ▸DELETE FROM table WHERE condition - remove data
- ▸CREATE TABLE table_name (columns) - define schema
FAQ
- ▸Is SQL open-standard? -> Yes, ANSI/ISO standard.
- ▸Does SQL work on all RDBMS? -> Core syntax is standard, but extensions vary.
- ▸Can SQL handle large datasets? -> Yes, with indexing and optimization.
- ▸Is SQL suitable for unstructured data? -> No, consider NoSQL for that.
- ▸How do you prevent SQL injection? -> Use parameterized queries and prepared statements.
30-Day Skill Plan
- ▸Week 1: Basic SELECT, INSERT, UPDATE, DELETE
- ▸Week 2: Joins, GROUP BY, and aggregate functions
- ▸Week 3: Subqueries, CTEs, and window functions
- ▸Week 4: Transactions, constraints, and indexing
- ▸Week 5: Performance tuning and backup strategies
Final Summary
- ▸SQL is the standard language for relational database management.
- ▸Enables querying, updating, and managing structured data.
- ▸Supports transactions, constraints, and complex joins.
- ▸Widely adopted in enterprise, analytics, and web applications.
- ▸Works with most RDBMS, with strong community and tooling support.
Project Structure
- ▸Database instance
- ▸Schemas for logical separation
- ▸Tables representing entities
- ▸Views for reusable queries
- ▸Stored procedures/functions for business logic
Monetization
- ▸Many RDBMS are open-source (MySQL, PostgreSQL, SQLite)
- ▸Enterprise editions (Oracle, SQL Server) provide advanced features
- ▸Core SQL skills valuable in IT, data, and analytics jobs
- ▸Optimized SQL improves application performance
- ▸Foundation for business intelligence and reporting
Productivity Tips
- ▸Use parameterized queries for security
- ▸Index frequently queried columns
- ▸Normalize data to reduce redundancy
- ▸Use views and stored procedures for reusable logic
- ▸Profile queries regularly for performance
Basic Concepts
- ▸Database - container for related tables
- ▸Table - collection of rows with defined columns
- ▸Row/Record - single entry in a table
- ▸Column/Field - attribute of a table with data type
- ▸Primary/Foreign Keys - enforce uniqueness and relationships
Official Docs
- ▸https://www.iso.org/standard/63555.html (SQL standard)
- ▸MySQL Documentation
- ▸PostgreSQL Documentation
- ▸Oracle SQL Reference
- ▸SQL Server Docs
More SQL Typing Exercises
PostgreSQL Advanced QueriesSQL Employee Management SystemSQL Employee Management SystemSQL Inventory ManagementSQL Customer SegmentationSQL Customer SegmentationSQL Financial Transactions AnalysisSQL Order Processing WorkflowSQL Order Processing WorkflowSQL Order Processing WorkflowSQL Healthcare Records ManagementSQL University Management System