| Start | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Auto Shop Database In the following example - Database for an auto shop business, we have a list of departments, employees, customers and customer cars. We are using foreign keys to create relationships between the various tables. Live example: SQL fiddle (opens new window) Relationships between tables
Departments
SQL statements to create the table: Employees
SQL statements to create the table: Customers
SQL statements to create the table: Cars
SQL statements to create the table: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Library Database In this example database for a library, we have Authors, Books and BooksAuthors tables. Live example: SQL fiddle (opens new window) Authors and Books are known as base tables, since they contain column definition and data for the actual entities in the relational model. BooksAuthors is known as the relationship table, since this table defines the relationship between the Books and Authors table. Relationships between tables
Authors(view table (opens new window))
SQL to create the table: Books(view table (opens new window))
SQL to create the table: BooksAuthors(view table (opens new window))
SQL to create the table: ExamplesView all authors (view live example (opens new window)): View all book titles (view live example (opens new window)): View all books and their authors (view live example (opens new window)): |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Countries Table In this example, we have a Countries table. A table for countries has many uses, especially in Financial applications involving currencies and exchange rates. Live example: SQL fiddle (opens new window) Some Market data software applications like Bloomberg and Reuters require you to give their API either a 2 or 3 character country code along with the currency code. Hence this example table has both the 2-character Countries(view table (opens new window))
SQL to create the table: |
Read Article
https://develop.horje.com/learn/1434/reference