smartyfy.mrindigi.com

Databases & SQL Master Course — 200. Final Assessment and Portfolio Handoff

Lesson 200 Final Assessment and Portfolio Handoff

Prerequisites and objectives

Complete Lesson 199 and review the earlier concepts named in this lesson. You will demonstrate the capstone’s requirements through executable checks, diagnose a plausible incorrect report, rehearse a guarded change and restore, and assemble an honest portfolio handoff. This final lesson is a practical assessment, not merely a completion announcement. The shared capstone is a fictional workshop-supply shop using one currency, USD cents. Every exercise scenario starts from a new copy of its displayed fixture; changes in another lesson are not assumed to persist.

Shared fixture dependency

Run the exact schema and seed from Lesson 193 in a new disposable SQLite database. The displayed setup is sufficient; no companion download is required. Any additional definition is shown below. Each exercise was verified from this baseline independently, not from the previous exercise’s final state.

Define what completion means for this capstone

The local deliverable is a reproducible fictional database exercise with an agreed model, constrained schema, baseline data, staged-load practice, operational queries, analytical reports, plan and construction review, and recovery evidence. Link every requirement to a result, rejected case, or documented limit.

Completing these local exercises does not establish deployment readiness, production performance, or server-role enforcement. Validate those separately in the appropriate environment.

Predict identities and amounts before reading the solutions. Run the exercises in fresh fixtures and explain mismatches before changing queries or expected values. Explain grain and assumptions alongside passing results.

Final local acceptance map
Requirement Evidence to present
Model and schema Keys, references, types, status and date boundaries
Correct reporting Baseline 2 orders / 6 units / 830 cents
Controlled change One accepted update, inspected retry, rollback
Recovery Separate copied file plus content and integrity checks

Connect the course’s core ideas

Relational fundamentals appear in the stable entities and keys. Query construction appears in joins, filters, grouped totals, and bound values. Modeling appears in historical line prices and current catalog state. Transactions appear in staged promotion and guarded changes. Recovery and observability appear in recorded checks and explicit execution scope.

Use advanced techniques for stated requirements: windows add cumulative context, while simple lookups need no window. Ordinary views expose query contracts, not authorization or stored-cache guarantees.

Exercise 1

Prove the baseline population, relationships, and paid measure.

Worked solution
-- Connection A
SELECT COUNT(*) FROM cap_customer;
SELECT COUNT(*) FROM cap_order;
PRAGMA foreign_key_check;
SELECT COUNT(DISTINCT o.id),SUM(l.units),SUM(l.units*l.unit_cents) FROM cap_order o JOIN cap_line l ON l.order_id=o.id WHERE o.status='paid';
SELECT c.id,COALESCE(SUM(l.units*l.unit_cents),0) AS paid_cents FROM cap_customer c LEFT JOIN cap_order o ON o.customer_id=c.id AND o.status='paid' LEFT JOIN cap_line l ON l.order_id=o.id GROUP BY c.id ORDER BY c.id;

The evidence distinguishes three stored orders from two paid orders and preserves all three customers. The paid value reconciles to the individual line arithmetic. State clearly that Bo and Cleo have zero accepted paid value for different reasons, and that the reference check covers relationships rather than every business rule.

Exercise 2

Demonstrate a controlled transition and restoration of the baseline.

Worked solution
-- Connection A
BEGIN IMMEDIATE;
-- Bind values through the client API: [11]
UPDATE cap_order SET status='paid' WHERE id=? AND status='open' AND EXISTS(SELECT 1 FROM cap_line WHERE order_id=cap_order.id);
-- Bind values through the client API: [11]
UPDATE cap_order SET status='paid' WHERE id=? AND status='open' AND EXISTS(SELECT 1 FROM cap_line WHERE order_id=cap_order.id);
SELECT COUNT(DISTINCT o.id),SUM(l.units),SUM(l.units*l.unit_cents) FROM cap_order o JOIN cap_line l ON l.order_id=o.id WHERE o.status='paid';
ROLLBACK;
SELECT COUNT(DISTINCT o.id),SUM(l.units),SUM(l.units*l.unit_cents) FROM cap_order o JOIN cap_line l ON l.order_id=o.id WHERE o.status='paid';

The accepted update changes the paid report predictably, the repeat changes no row, and rollback restores the known baseline. Explain why zero affected rows requires state interpretation and why this database-only transition does not prove an external payment occurred.

Exercise 3

Diagnose a report that incorrectly reprices historical lines from the catalog.

Worked solution
-- Connection A
SELECT SUM(l.units*p.list_cents) FROM cap_line l JOIN cap_order o ON o.id=l.order_id JOIN cap_product p ON p.id=l.product_id WHERE o.status='paid';
SELECT l.order_id,l.line_no,l.units*l.unit_cents AS charged,l.units*p.list_cents AS repriced FROM cap_line l JOIN cap_order o ON o.id=l.order_id JOIN cap_product p ON p.id=l.product_id WHERE o.status='paid' AND l.unit_cents<>p.list_cents ORDER BY l.order_id,l.line_no;

The incorrect query reports nine hundred cents, seventy above the historical control. Two PEN lines explain the difference: forty and thirty cents. The correction is to use historical line price for this measure, not to edit the catalog or remove inconvenient rows until totals agree.

Exercise 4

Copy the baseline and verify both content and an enforced relationship.

Worked solution
-- Connection A
-- Use a client implementing the SQLite Online Backup API to copy this source into a NEW separate database opened as connection R; wait for successful completion.
-- Connection R
PRAGMA foreign_keys=ON;
PRAGMA integrity_check;
SELECT COUNT(DISTINCT o.id),SUM(l.units),SUM(l.units*l.unit_cents) FROM cap_order o JOIN cap_line l ON l.order_id=o.id WHERE o.status='paid';
INSERT INTO cap_line VALUES(11,2,99,1,100);
PRAGMA foreign_key_check;

The separate copy opens, has the accepted paid controls, and rejects a new orphan after enforcement is enabled on the restored connection. This is stronger than merely observing that a backup file exists. It remains a local fictional restore test, not a production failover or disaster-recovery certification.

Assemble a portfolio someone else can rerun

Include the requirement sheet, conceptual diagram specification, schema DDL, fixture, staged-load rules, operational and analytical SQL, expected outputs, and verification record. A downloadable package with capstone-base.sql and capstone-practice.sql is planned but not linked here. Lesson 193’s displayed setup suffices for these exercises.

Add a data dictionary and runbook identifying minimum SQLite version, per-connection foreign-key configuration, monetary units, source-key meaning, accepted statuses, date-validation boundary, and the difference between current and historical prices. Name every client-side step, especially backup operations, rather than pretending comments execute those actions.

Keep the final package’s SQL and results tied to their source version. If the schema, fixture, or query changes after review, rerun the relevant tests and document the amendment. Do not silently replace an already reviewed artifact while leaving its older evidence or hashes attached.

Assess understanding with evidence, not a badge

A strong submission explains each output grain, justifies predicate placement, handles ties and absence, identifies failed preconditions, and distinguishes observed results from reasoned expectations. It also identifies which rules remain in the application and which are enforced by the database.

Server examples retain documentation-only labels where their engines were absent.

Pitfalls and summary

Finish with runnable evidence, clear definitions, and bounded claims. Preserve historical facts, inspect guarded outcomes, reject false reassurance from balanced totals or successful file copies, and hand over the materials needed to reproduce and maintain the work.

Knowledge check

Question 1

Which evidence best supports the historical paid total?

  1. The current catalog repricing query returns a larger total
  2. Accepted line identities and their stored unit prices reconcile to 830 cents
  3. The database file opens without error
  4. Every source row has an integer identity
Answer and explanation

B. Correct measure definitions and row-level reconciliation support the monetary result.

Question 2

Why is the 900-cent query wrong for this requirement?

  1. It substitutes current catalog prices for historical charged prices
  2. It counts only open orders
  3. It omits both PEN lines
  4. It uses a bound value instead of a literal
Answer and explanation

A. The two repriced PEN lines create the seventy-cent discrepancy.

Question 3

What does a successful rollback demonstrate in the transition trial?

  1. A real payment provider also reversed a charge
  2. Every external side effect is automatically undone
  3. The local database changes return to the verified baseline
  4. The same behavior is proven on unexecuted server engines
Answer and explanation

C. Transaction evidence is scoped to the database operation actually exercised.

Question 4

Which handoff claim is justified?

  1. The complete shop service is production-ready
  2. A successful database copy proves the complete service-recovery target
  3. Every PostgreSQL and MySQL script was executed
  4. The supplied local SQL fixtures and checks have recorded execution evidence
Answer and explanation

D. Authorship, local execution, deployment, and asset delivery are distinct statuses.

Question 5

What should follow a post-review schema or query change?

  1. Reuse old hashes because the lesson number is unchanged
  2. Update expected outputs without examining the new behavior
  3. A documented amendment and rerun of affected checks
  4. Silently replace the reviewed artifact and retain its old evidence
Answer and explanation

C. Versioned evidence must match the actual delivered content.

Execution scope

These scenarios were executed with SQLite 3.53.1 using separate connections to newly created disposable local database files. No existing or external database was used. Each scenario starts from a fresh fixture. Python was an internal verification harness, not a learner prerequisite. A and B open the source file; each R-labeled connection opens its own new separate backup or restored file. Backup labels are client API operations executed by the verification harness, not SQL commands.

Primary references