The Data Studio

Code Samples For Relational Databases For Agile Developers

From this page you can download code samples for the book Relational Databases For Agile Developers

You can use these as you choose. All the samples have been tested, but you use them entirely at your own risk. We take no reponsibility for what you do with them.

The files are all plain text source code: SQL scripts, Bash shell scripts, user-defined functions, Java source code, Ruby on Rails scripts or data. You need to understand them before you use them, especially the bash shell scripts. They are written with normal precautions against doing anything bad, but if you download code from here and run it, you must take responsibility for what happens.

You can download a tar or zip archive of all the samples referenced in the book, or access the individual files.

Compressed tar file, usually better for for UNIX and Mac compressed tar file
Zipped file, usually better for Windows zip file

Individual Files

Chapter Section Download link
Chapter 1 - Learning to Drive Your Database One Value in Each Cell compound_field.xml
Chapter 1 - Learning to Drive Your Database One Value in Each Cell atomic_fields.xml
Chapter 1 - Learning to Drive Your Database One Value in Each Cell count_drivers_by_policy.sql
Chapter 1 - Learning to Drive Your Database One Value in Each Cell accounts_and_postings.xml
Chapter 1 - Learning to Drive Your Database One Value in Each Cell postings_within_accounts.xml
Chapter 1 - Learning to Drive Your Database One Value in Each Cell order_by_policy_number.sql
Chapter 1 - Learning to Drive Your Database One Value in Each Cell order_by_transaction_type_and_effective_time.sql
Chapter 1 - Learning to Drive Your Database One Value in Each Cell order_by_amount_descending.sql
Chapter 3 - An Agile Database - Step by Step Iteration 1 scaffold_iteration_1.sh
Chapter 3 - An Agile Database - Step by Step Iteration 1 LimitPolicyNumberSize.rb
Chapter 3 - An Agile Database - Step by Step Iteration 1 ClaimantsClaimIdAndPersonIdNotNull.rb
Chapter 3 - An Agile Database - Step by Step Iteration 2 AddColumnsToVehicle.rb
Chapter 3 - An Agile Database - Step by Step Iteration 2 scaffold_iteration_2.sh
Chapter 3 - An Agile Database - Step by Step Iteration 2 RemoveIncidentColumnsFromClaim.rb
Chapter 3 - An Agile Database - Step by Step Iteration 2 ClaimBelongsToIncident.rb
Chapter 3 - An Agile Database - Step by Step Iteration 3 scaffold_iteration_3_claim_head.sh
Chapter 3 - An Agile Database - Step by Step Iteration 3 scaffold_iteration_3_transaction.sh
Chapter 3 - An Agile Database - Step by Step Iteration 3 LimitClaimHeadCodeAndDescription.rb
Chapter 3 - An Agile Database - Step by Step Iteration 3 LimitTransactionColumns.rb
Chapter 4 - Database Migrations In SQL Database Migration for Iteration 1 person.sql
Chapter 4 - Database Migrations In SQL Database Migration for Iteration 1 policy.sql
Chapter 4 - Database Migrations In SQL Database Migration for Iteration 1 vehicle.sql
Chapter 4 - Database Migrations In SQL Database Migration for Iteration 1 claim.sql
Chapter 4 - Database Migrations In SQL Database Migration for Iteration 1 claimant.sql
Chapter 4 - Database Migrations In SQL Database Migration for Iteration 1 witness.sql
Chapter 4 - Database Migrations In SQL Database Migration for Iteration 1 driver.sql
Chapter 4 - Database Migrations In SQL Database Migration for Iteration 1 passenger.sql
Chapter 4 - Database Migrations In SQL Database Migration for Iteration 1 damage.sql
Chapter 4 - Database Migrations In SQL Database Migration for Iteration 1 migration_001.sql
Chapter 4 - Database Migrations In SQL Database Migration for Iteration 2 migration_002.sql
Chapter 4 - Database Migrations In SQL Database Migration for Iteration 3 claim_head.sql
Chapter 4 - Database Migrations In SQL Database Migration for Iteration 3 transaction.sql
Chapter 4 - Database Migrations In SQL Database Migration for Iteration 3 migration_003.sql
Chapter 6 - Data Types Simple Data-Types close_enough.sql
Chapter 6 - Data Types Data-Types That Contain Their Own Internal Structure bordereau.xml
Chapter 7 - Nulls Data-Types That Contain Their Own Internal Structure missing_name.sql
Chapter 7 - Nulls Data-Types That Contain Their Own Internal Structure null_never_equals_anything.sql
Chapter 7 - Nulls Arithmetic show_table_nulls_in_arithmetic.sql
Chapter 7 - Nulls Arithmetic nulls_in_arithmetic.sql
Chapter 7 - Nulls Aggregates find_null.sql
Chapter 7 - Nulls Aggregates aggregate_null.sql
Chapter 7 - Nulls Joins ... join_null.sql
Chapter 7 - Nulls ...and Set Operators intersect_null.sql
Chapter 7 - Nulls ...and Set Operators except_null.sql
Chapter 7 - Nulls ...and Set Operators coalesce_null.sql
Chapter 7 - Nulls Strings null_vs_empty_postgres.sql
Chapter 7 - Nulls Strings null_vs_empty_oracle.sql
Chapter 7 - Nulls Inserts and Updates update_null.sql
Chapter 7 - Nulls Java null_java.sql
Chapter 9 - Select From One Table Your First Select Statement select_vehicle_columns.sql
Chapter 9 - Select From One Table Your First Select Statement select_person_where.sql
Chapter 9 - Select From One Table Your First Select Statement select_minneapolis.sql
Chapter 9 - Select From One Table Pattern Matching select_any_case.sql
Chapter 9 - Select From One Table Pattern Matching select_like.sql
Chapter 9 - Select From One Table Pattern Matching select_like_zip_code.sql
Chapter 9 - Select From One Table Sorting select_order_by.sql
Chapter 9 - Select From One Table Grouping and Aggregating select_group_by_claimant.sql
Chapter 9 - Select From One Table Grouping and Aggregating select_all_aggregates.sql
Chapter 9 - Select From One Table Grouping and Aggregating select_count_options.sql
Chapter 9 - Select From One Table Grouping and Aggregating select_group_multiple.sql
Chapter 9 - Select From One Table Grouping and Aggregating select_having.sql
Chapter 9 - Select From One Table Window Functions track.sql
Chapter 9 - Select From One Table Window Functions current_and_previous_odometer.sql
Chapter 9 - Select From One Table Window Functions distance_travelled.sql
Chapter 9 - Select From One Table Window Functions row_count_and_rank.sql
Chapter 9 - Select From One Table Window Functions median.sql
Chapter 10 - Select From Many Tables Joining Data from Multiple Tables join_simple.sql
Chapter 10 - Select From Many Tables Joining Data from Multiple Tables join_named_table.sql
Chapter 10 - Select From Many Tables Joining Data from Multiple Tables join_where.sql
Chapter 10 - Select From Many Tables Joining Data from Multiple Tables join_three_tables.sql
Chapter 10 - Select From Many Tables Joining Incomplete Sets join_outer.sql
Chapter 10 - Select From Many Tables Joining Incomplete Sets join_outer_three_tables.sql
Chapter 10 - Select From Many Tables Joining Incomplete Sets join_full_outer.sql
Chapter 10 - Select From Many Tables Joining Incomplete Sets join_coalesce.sql
Chapter 10 - Select From Many Tables Joining Incomplete Sets union.sql
Chapter 10 - Select From Many Tables Joining Incomplete Sets union_all.sql
Chapter 10 - Select From Many Tables Joining Incomplete Sets except.sql
Chapter 10 - Select From Many Tables Joining Incomplete Sets intersect.sql
Chapter 10 - Select From Many Tables Joining Incomplete Sets union_as.sql
Chapter 10 - Select From Many Tables Joining Incomplete Sets find_broken_link.sql
Chapter 10 - Select From Many Tables Joining Incomplete Sets join_cars_drivers.sql
Chapter 10 - Select From Many Tables Joining Incomplete Sets delete_vehicle.sql
Chapter 10 - Select From Many Tables Joining Incomplete Sets drop_foreign_key_constraint.sql
Chapter 10 - Select From Many Tables Joining Incomplete Sets delete_vehicle.sql
Chapter 10 - Select From Many Tables Joining Incomplete Sets find_broken_link.sql
Chapter 10 - Select From Many Tables Joining Incomplete Sets case_expression.sql
Chapter 10 - Select From Many Tables Joining Incomplete Sets case_multi_factor.sql
Chapter 10 - Select From Many Tables Nested Queries nested_percentage.sql
Chapter 10 - Select From Many Tables Nested Queries nested_count.sql
Chapter 10 - Select From Many Tables Nested Queries nested_sub_query.sql
Chapter 10 - Select From Many Tables Nested Queries nested_sub_query_where.sql
Chapter 10 - Select From Many Tables Nested Queries nested_compare_many.sql
Chapter 10 - Select From Many Tables Nested Queries create_for_pivot.sql
Chapter 10 - Select From Many Tables Nested Queries select_for_pivot.sql
Chapter 11 - Populating Your Database Insert insert_person.sql
Chapter 11 - Populating Your Database Insert insert_dinsdale.sql
Chapter 11 - Populating Your Database Update update_flynn.sql
Chapter 11 - Populating Your Database Update update_jdbc.sql
Chapter 11 - Populating Your Database Update update_from_table.sql
Chapter 11 - Populating Your Database Update update_from_table_oracle.sql
Chapter 11 - Populating Your Database Delete delete.sql
Chapter 12 - Database Migrations That Preserve Data Iteration 2 alter_vehicle.sql
Chapter 12 - Database Migrations That Preserve Data Iteration 2 test_claim_counts.sql
Chapter 12 - Database Migrations That Preserve Data Iteration 2 test_incident_counts.sql
Chapter 12 - Database Migrations That Preserve Data Iteration 2 test_no_data_lost.sql
Chapter 12 - Database Migrations That Preserve Data Iteration 2 test_no_data_duplicated.sql
Chapter 12 - Database Migrations That Preserve Data Iteration 2 test_claim_sequence_and_id.sql
Chapter 12 - Database Migrations That Preserve Data Iteration 2 test_incident_sequence_and_id.sql
Chapter 12 - Database Migrations That Preserve Data Iteration 2 drop_claim_constraints.sql
Chapter 12 - Database Migrations That Preserve Data Iteration 2 rename_claim_to_old_claim.sql
Chapter 12 - Database Migrations That Preserve Data Iteration 2 create_incident_table.sql
Chapter 12 - Database Migrations That Preserve Data Iteration 2 populate_incident_table.sql
Chapter 12 - Database Migrations That Preserve Data Iteration 2 create_new_claim_table.sql
Chapter 12 - Database Migrations That Preserve Data Iteration 2 populate_new_claim_table.sql
Chapter 12 - Database Migrations That Preserve Data Iteration 2 reset_claim_sequence.sql
Chapter 12 - Database Migrations That Preserve Data Iteration 2 reset_incident_sequence.sql
Chapter 12 - Database Migrations That Preserve Data Iteration 2 reinstate_foreign_keys.sql
Chapter 12 - Database Migrations That Preserve Data Iteration 2 migration_preserve_data.sql
Chapter 13 - When Things Go Wrong "Something Went Wrong" java_exception.java
Chapter 13 - When Things Go Wrong "Something Went Wrong" java_exception_extra.java
Chapter 13 - When Things Go Wrong "Something Went Wrong" java_exception_bad.java
Chapter 14 - Tuning Keep Database Navigation in the Database, Not in the Application database_navigation_bad.java
Chapter 14 - Tuning Keep Database Navigation in the Database, Not in the Application database_navigation_good.java
Chapter 15 - Metadata Accessing Metadata In an Application list_schemas.java
Chapter 15 - Metadata Using Metadata To Profile Your Database list_tables.java
Chapter 15 - Metadata Using Metadata To Profile Your Database list_metadata.java
Chapter 16 - Universal Data Models Abstract Data Models find_entity_attributes.sql
Chapter 16 - Universal Data Models Abstract Data Models reassemble_table.sql
Chapter 16 - Universal Data Models Abstract Data Models select_policy_data.sql
Chapter 18 - Database Features To Be Wary Of User-Defined Functions and Stored Procedures luhn_check_passed.sql
Chapter 18 - Database Features To Be Wary Of Create Table As Select create_table_as_select.sql