Last Sync: 2022-08-05 09:00:04
This commit is contained in:
parent
ba1f542fac
commit
feb2c5fddb
5 changed files with 35 additions and 31 deletions
|
@ -1,11 +1,11 @@
|
|||
---
|
||||
tags:
|
||||
- Programming_Languages
|
||||
- Databases
|
||||
---
|
||||
|
||||
|
||||
>
|
||||
# Fundamental database concepts
|
||||
|
||||
> A database is a collection of organised data that can be efficiently stored, sorted, and searched.
|
||||
|
||||
How the data is organised will often determine the *type* of database used. There are many different types of database; some examples of the different types are relational, object-orientated, graphical, NoSQL, and distributed.
|
||||
|
@ -15,7 +15,7 @@ How the data is organised will often determine the *type* of database used. Ther
|
|||
To ensure the integrity of a database, each change or transaction must conform to a set of rules known as ACID:
|
||||
|
||||
* **atomicity**
|
||||
* when changing data within a database, if any part of the change fails, the whole change will fail and the data will remain as it was before the change was made; this prevents partial records being created. Basically a safeguard
|
||||
* when changing data within a database, if any part of the change fails, the whole change will fail and the data will remain as it was before the change was made; this is a safeguard that prevents partial records being created.
|
||||
* **consistency**
|
||||
* before data can be changed in a database, it must be validated against a set of rules
|
||||
* **isolation**
|
||||
|
@ -31,25 +31,3 @@ To ensure the integrity of a database, each change or transaction must conform t
|
|||
A DBMS is software that can retrieve, add, and alter existing data in a database. MySQL, PostgreSQL, MongoDB, MariaDB are all examples of DBMSs. You can work with them via programming languages like PHP or through graphical clients such as PHPMyAdmin, MicrosoftSQL, Adminer etc. There is also SQLite which runs on the client not the server, so useful for learning and local development. SQLite is also useful when you need a database specific to a single device without networked communication, such as on mobile.
|
||||
|
||||
There are also CLI tools for all the major databases.
|
||||
|
||||
While I will be working primarily through PHP, graphical database software is useful for visual grepping and checking that scripts are working as they should.
|
||||
|
||||
## Relational database architecture
|
||||
|
||||
Tables, fields and records are the basic building blocks of databases
|
||||
|
||||

|
||||
|
||||
### Table
|
||||
|
||||
A group of similar data with rows for **records** and columns for each **field**.
|
||||
|
||||
### Record
|
||||
|
||||
Horizontal/"row": a collection of items which may be of different data types all relating to the individual or object that the record describes
|
||||
|
||||
### Field
|
||||
|
||||
Vertical/ "column" : stores a single particular unit of data for each record. Each field must use the same data type.
|
||||
|
||||
Each individual field has **properties:** such as the data type, length or the total memory allocation.
|
0
Databases/MongoDB/Introduction.md
Normal file
0
Databases/MongoDB/Introduction.md
Normal file
|
@ -2,15 +2,16 @@
|
|||
tags:
|
||||
- Programming_Languages
|
||||
- Databases
|
||||
- relational_databases
|
||||
---
|
||||
|
||||
# Primary key
|
||||
|
||||
>
|
||||
> Every table in a relational database should have a **primary key**. A primary key is one **field that uniquely identifies each record**.
|
||||
|
||||
This is essential for carrying out operations across database tables and for creating and deleting database entires. It is also a safeguard: it means you can always identify a record by itself and don't have to rely on generic queries to identify it.
|
||||
|
||||
Sometimes you will have a dedicated field such as `UNIQUE_ID` for the primary key. Other times you can use an existing field to fulfil that function (a bit like using the `key` attribute in React). In both cases the following constraints **must be met:**
|
||||
Sometimes you will have a dedicated field such as `UNIQUE_ID` for the primary key. Other times you can use an existing field to fulfil that function. In both cases the following constraints **must be met:**
|
||||
|
||||
1. No two records can have the **same** primary key data
|
||||
1. The primary key value should **never be reused**. Thus, if a record is deleted from the table, it should not be re-allocated to a new record.
|
||||
|
|
23
Databases/Relational_database_architecture.md
Normal file
23
Databases/Relational_database_architecture.md
Normal file
|
@ -0,0 +1,23 @@
|
|||
---
|
||||
tags:
|
||||
- Databases
|
||||
---
|
||||
|
||||
# Relational database architecture
|
||||
Tables, fields and records are the basic building blocks of databases
|
||||
|
||||

|
||||
|
||||
## Table
|
||||
|
||||
A group of similar data with rows for **records** and columns for each **field**.
|
||||
|
||||
## Record
|
||||
|
||||
A horizontal row: a collection of items which may be of different data types all relating to the individual or object that the record describes
|
||||
|
||||
### Field
|
||||
|
||||
A vertical column: stores a single particular unit of data for each record. Each field must use the same data type.
|
||||
|
||||
Each individual field has **properties:** such as the data type, length or the total memory allocation.
|
|
@ -5,13 +5,15 @@ tags:
|
|||
- sql
|
||||
---
|
||||
|
||||
# SQL syntax
|
||||
|
||||
## Demonstration database
|
||||
|
||||
For the purposes of demonstration we will work from a made up database. This database stores information about computers, their manufacturers, properties and sale data:
|
||||
For the purposes of demonstration we will work from a made-up database. This database stores information about computers, their manufacturers, properties and sale data:
|
||||
|
||||
* Overall database: **`computer_sales`**
|
||||
* Tables: `**manufacturer**` , `**model**` , `**sales**`
|
||||
* Example fields: `**manufacturer_id**` , `**model_id**` , `**name**`, `**year_founded**` , `**ram**` , `**sale_date**`
|
||||
* The overall database is `computer_sales`
|
||||
* It contains the following [tables](/Databases/Relational_database_architecture.md#table): `manufacturer` , `model` , `sales`
|
||||
* Example [fields](/Databases/Relational_database_architecture.md#field) that belong to these tables: `manufacturer_id` , `model_id` , `name`, `year_founded` , `ram` , `sale_date`
|
||||
|
||||
Below are the `model` and `manufacturer` tables output from the SQLite terminal client.
|
||||
|
Loading…
Add table
Reference in a new issue