Sql

SQL Relational Model

A relational database defines relationships in the form of tables.

  • data is organized into relations (called tables in SQL), where each relation is an unordered collection of tuples

SQL programming can be effectively used to insert, search, update, delete database records.

  • vertically scalable: adding more power (CPU, RAM) to an existing machine.

good

many-to-one, use id

The advantage of using an ID is that because it has no meaning to humans, it never needs to change: the ID can remain the same, even if the information it identifies changes. Anything that is meaningful to humans may need to change sometime in the future—and if that information is duplicated, all the redundant copies need to be updated. That incurs write overheads, and risks inconsistencies (where some copies of the information are updated but others aren’t). Removing such duplication is the key idea behind normalization in databases.

Problem

Most application development today is done in object-oriented programming lan‐guages, which leads to a common criticism of the SQL data model: if data is stored in relational tables, an awkward translation layer is required between the objects in the application code and the database model of tables, rows, and columns. The discon‐nect between the models is sometimes called an impedance mismatch.

If you want to fetch a profile in the relational example, you need to either perform multiple queries (query each table by user_id) or perform a messy multiway join between the users table and its subordinate tables.