|
| 1 | +# Example Database Schemas |
| 2 | + |
| 3 | +This repository contains a handful of example database schemas. We want this |
| 4 | +repository to do two things: |
| 5 | + |
| 6 | +1. Serve as a reference for common schema design patterns |
| 7 | +2. Give students more exposure to schema-level SQL, e.g., |
| 8 | + `CREATE TABLE`, `CREATE UNIQUE INDEX`, and so on. |
| 9 | + |
| 10 | +## Format of This Repository |
| 11 | + |
| 12 | +Every schema is contained in its own directory. For example, the |
| 13 | +[blog_with_tags](blog_with_tags) directory contains a schema for a very basic |
| 14 | +blog with support for tagging blog posts. In this example, the schema itself is |
| 15 | +contained in a file named |
| 16 | + |
| 17 | +```text |
| 18 | +blog_with_tags.postgres.sql |
| 19 | +``` |
| 20 | + |
| 21 | +which contains raw SQL `CREATE TABLE` statements that define the various tables, |
| 22 | +indexes, and associations that make up the database schema. |
| 23 | + |
| 24 | +The file is named `.postgres.sql` because the SQL statements contained inside |
| 25 | +follow PostgreSQL's dialect of SQL. Every database engine has its own "dialect" |
| 26 | +of SQL, whether the engine MySQL, SQLite3, Microsoft SQL Server, or Oracle. |
| 27 | + |
| 28 | +We'll be adding examples in other dialects as time goes on. If you want to |
| 29 | +help the process along, [we welcome pull requests][pull-request-url] |
| 30 | + |
| 31 | +## Schemas in This Repository |
| 32 | + |
| 33 | +### Blog With Tags |
| 34 | + |
| 35 | +The [blog_with_tags](blog_with_tags) schema models a basic blog where users can |
| 36 | +publish articles and tag them with arbitrary tags. It defines users, articles, |
| 37 | +and tags. |
| 38 | + |
| 39 | +### Blog With Likes |
| 40 | + |
| 41 | +The [blog_with_likes](blog_with_likes) schema models a basic blog where users |
| 42 | +can publish new articles or like already-published articles. It defines users, |
| 43 | +articles, and likes. |
| 44 | + |
| 45 | +### Question and Answer |
| 46 | + |
| 47 | +The [question_and_answer](question_and_answer) schema models a basic Q&A site |
| 48 | +a la Stack Overflow or Yahoo! Answers. It defines users, questions, answers, |
| 49 | +and voting. |
| 50 | + |
| 51 | +### Surveys |
| 52 | + |
| 53 | +The [surveys](surveys) schema models a website where users can create surveys |
| 54 | +for other users to fill out. It defines users, surveys, survey choices, and |
| 55 | +survey responses. |
| 56 | + |
| 57 | +### Reddit |
| 58 | + |
| 59 | +The [reddit](reddit) schema models a Reddit-like site where users submit links |
| 60 | +for other to vote and comment on. It defines users, link submissions, voting, |
| 61 | +and nested commenting. |
| 62 | + |
| 63 | +### Photo Gallery |
| 64 | + |
| 65 | +The [photo_gallery](photo_gallery) schema models a basic photo gallery. Users |
| 66 | +can create albums and upload photos to a specific album. |
| 67 | + |
| 68 | +### Hangman |
| 69 | + |
| 70 | +The [hangman](hangman) schema models a player vs. computer version of |
| 71 | +[letter-guessing game Hangman](http://en.wikipedia.org/wiki/Hangman_%28game%29). |
| 72 | +It defines users, games, turns, and phrases. |
| 73 | + |
| 74 | +### Tic Tac Toe |
| 75 | + |
| 76 | +The [tic_tac_toe](tic_tac_toe) schema models a collection of tic-tac-toe games. |
| 77 | +It defines users, games, and turns. |
| 78 | + |
| 79 | +[pull-request-url]: https://github.com/codeunion/examples-schema/pulls |
0 commit comments