• Stars
    star
    370
  • Rank 115,405 (Top 3 %)
  • Language PLpgSQL
  • License
    BSD 2-Clause "Sim...
  • Created over 3 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The Sakila Database

The Sakila example database

The Sakila database is a nicely normalised database modelling a DVD rental store (for those of you old enough to remember what that is). Its design includes a few nice features:

  • Many to many relationships
  • Multiple paths between entities (e.g. film-inventory-rental-payment vs film-inventory-store-customer-payment) to practice joins
  • Consistent naming of columns
    • Primary keys are called [tablename]_[id]
    • Foreign keys are called like their referenced primary key, if possible. This allows for using JOIN .. USING syntax where supported
    • Relationship tables do not have any surrogate keys but use composite primary keys
    • Every table has a last_update audit column
    • A generated data set of a reasonable size is available

ERD

ERD

With this database, we can try out some nice SQL queries, e.g. by using PostgreSQL syntax:

Actor with most films (ignoring ties)

SELECT first_name, last_name, count(*) films
FROM actor AS a
JOIN film_actor AS fa USING (actor_id)
GROUP BY actor_id, first_name, last_name
ORDER BY films DESC
LIMIT 1;

Yields:

first_name    last_name    films
--------------------------------
GINA          DEGENERES       42

Cumulative revenue of all stores

SELECT payment_date, amount, sum(amount) OVER (ORDER BY payment_date)
FROM (
  SELECT CAST(payment_date AS DATE) AS payment_date, SUM(amount) AS amount
  FROM payment
  GROUP BY CAST(payment_date AS DATE)
) p
ORDER BY payment_date;

Yields:

payment_date       amount         sum
-------------------------------------
2005-05-24          29.92       29.92
2005-05-25         573.63      603.55
2005-05-26         754.26     1357.81
2005-05-27         685.33     2043.14
2005-05-28         804.04     2847.18
2005-05-29         648.46     3495.64
2005-05-30         628.42     4124.06
2005-05-31         700.37     4824.43
2005-06-14          57.84     4882.27
2005-06-15        1376.52     6258.79
2005-06-16        1349.76     7608.55
2005-06-17        1332.75     8941.30
...

History

The Sakila example database was originally developed by Mike Hillyer of the MySQL AB documentation team. it was ported to other databases by DB Software Laboratory

License: BSD Copyright DB Software Laboratory http://www.etl-tools.com

More Repositories

1

jOOQ

jOOQ is the best way to write SQL in Java
Java
6,078
star
2

jOOR

jOOR - Fluent Reflection in Java jOOR is a very simple fluent API that gives access to your Java Class structures in a more intuitive way. The JDK's reflection APIs are hard and verbose to use. Other languages have much simpler constructs to access type meta information at runtime. Let us make Java reflection better.
Java
2,797
star
3

jOOL

jOOλ - The Missing Parts in Java 8 jOOλ improves the JDK libraries in areas where the Expert Group's focus was elsewhere. It adds tuple support, function support, and a lot of additional functionality around sequential Streams. The JDK 8's main efforts (default methods, lambdas, and the Stream API) were focused around maintaining backwards compatibility and implementing a functional API for parallelism.
Java
2,074
star
4

jOOX

jOOX - The Power of jQuery Applied to W3C DOM Like JDBC, DOM is a powerful, yet very verbose low-level API to manipulate XML. The HTML DOM an be manipulated with the popular jQuery product, in JavaScript. Why don't we have jQuery in Java? jOOX is jQuery's XML parts, applied to Java.
Java
491
star
5

jOOU

jOOU - Unsigned Integers jOOU provides unsigned integer versions for the four Java integer types byte, short, int and long.
Java
223
star
6

jOOQ-mcve

A simple example project that can be used to create MCVE's to report jOOQ issues
Kotlin
23
star
7

demo

A jOOQ demo working with the Sakila database
Scala
15
star
8

sql-scripts

Some fun and useful SQL scripts
9
star
9

jbang-example

A quick example to get up and running with jbang
Java
7
star
10

sql-benchmarks

A set of SQL benchmark code snippets that are used on the jOOQ blog
TSQL
6
star
11

jbang-catalog

A catalog for jbang commands
Java
1
star