From feb2c5fddb5df830186fae398a89f27e56512230 Mon Sep 17 00:00:00 2001 From: tactonbishop Date: Fri, 5 Aug 2022 09:00:04 +0100 Subject: [PATCH] Last Sync: 2022-08-05 09:00:04 --- ...ts.md => Fundamental_database_concepts.md} | 28 ++----------------- Databases/MongoDB/Introduction.md | 0 Databases/Primary_key.md | 5 ++-- Databases/Relational_database_architecture.md | 23 +++++++++++++++ Databases/{ => SQL}/SQL_syntax.md | 10 ++++--- 5 files changed, 35 insertions(+), 31 deletions(-) rename Databases/{Basic_database_concepts.md => Fundamental_database_concepts.md} (63%) create mode 100644 Databases/MongoDB/Introduction.md create mode 100644 Databases/Relational_database_architecture.md rename Databases/{ => SQL}/SQL_syntax.md (97%) diff --git a/Databases/Basic_database_concepts.md b/Databases/Fundamental_database_concepts.md similarity index 63% rename from Databases/Basic_database_concepts.md rename to Databases/Fundamental_database_concepts.md index f3cc23e..604be7e 100644 --- a/Databases/Basic_database_concepts.md +++ b/Databases/Fundamental_database_concepts.md @@ -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 - -![FL-Databases-1.5_terminology 1.gif](../img/FL-Databases-1.5_terminology%201.gif) - -### 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. diff --git a/Databases/MongoDB/Introduction.md b/Databases/MongoDB/Introduction.md new file mode 100644 index 0000000..e69de29 diff --git a/Databases/Primary_key.md b/Databases/Primary_key.md index 9ad3610..59a6d94 100644 --- a/Databases/Primary_key.md +++ b/Databases/Primary_key.md @@ -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. diff --git a/Databases/Relational_database_architecture.md b/Databases/Relational_database_architecture.md new file mode 100644 index 0000000..0dc5014 --- /dev/null +++ b/Databases/Relational_database_architecture.md @@ -0,0 +1,23 @@ +--- +tags: + - Databases +--- + +# Relational database architecture +Tables, fields and records are the basic building blocks of databases + +![](/img/FL-Databases-1.5_terminology.gif) + +## 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. diff --git a/Databases/SQL_syntax.md b/Databases/SQL/SQL_syntax.md similarity index 97% rename from Databases/SQL_syntax.md rename to Databases/SQL/SQL_syntax.md index 763bcb1..826aa8f 100644 --- a/Databases/SQL_syntax.md +++ b/Databases/SQL/SQL_syntax.md @@ -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.