Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed text what-is-sql-database.md #2179

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions src/content/lesson/what-is-sql-database.es.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SELECT username FROM user WHERE email='[email protected]'

En un mundo en el que la presencia de datos es cada vez más protagonista por su importante impacto sobre la toma de decisiones y la proliferación de procesos de negocio guiados por los datos y la información, las bases de datos son la mejor manera de almacenarlos. De hecho, un componente fundamental en la industria 4.0 es, precisamente, esta tecnología. A partir de los datos podremos llevar a cabo procesos de Data Mining, Machine Learning y automatizaciones, pero todo parte de las bases de datos.

El origen de las bases de datos eran los ficheros `.txt` y `.csv`, que si bien permitían almacenar una gran cantidad de información, los datos eran fáciles de corromper y de difícil acceso.
El origen de las bases de datos eran los ficheros `.txt` y `.csv`, que si bien permitían almacenar una gran cantidad de información, los datos se podían corromper con facilidad y eran de difícil acceso.

![Edgar Codd](https://github.com/breatheco-de/content/blob/master/src/assets/images/11fcd6d8-6177-4f42-b4e0-7b6475f24b0a.jpeg?raw=true)

Expand Down Expand Up @@ -55,23 +55,23 @@ Una tabla puede contener un amplio conjunto de filas y columnas. De su tamaño d

### Relaciones entre tablas

Una base de datos es una colección de tablas interconectadas. La conexión entre dos tablas se denomina `relación` y puede ser una de las siguientes:
Una base de datos es una colección de tablas interconectadas. La conexión entre dos tablas se denomina "relación" y puede ser una de las siguientes:

**Una a una:**
#### Una a una:

El ejemplo perfecto es la base de datos de la seguridad social, probablemente esta base de datos tiene una tabla llamada Contribuyente que contiene toda la información acerca de cada persona con un número de seguridad social y otra tabla con las Declaraciones De Impuestos del año en curso: **Una persona puede tener solo una declaración y solo una declaración puede ser hecha por una persona.**
El ejemplo perfecto es la base de datos de la seguridad social, probablemente esta base de datos tiene una tabla llamada **Contribuyente** (*TaxPayer*) que contiene toda la información acerca de cada persona con un número de seguridad social y otra tabla con las Declaraciones De Impuestos del año en curso: **Una persona puede tener solo una declaración y solo una declaración puede ser hecha por una persona.**

![SQL una a una](https://github.com/breatheco-de/content/blob/master/src/assets/images/6f51ce02-3a75-4027-ada5-cf63c50d1701.png?raw=true)

**Una a muchos:**
#### Una a muchos:

La base de datos de las Grandes Ligas en Baseball probablemente tiene una tabla llamada Jugadores (con la lista de todos los jugadores activos) y otra tabla llamada Equipos con la lista de todos los equipos activos. Ambas tablas están conectadas porque **un equipo tiene muchos jugadores, pero un jugador puede estar en un solo equipo.**
La base de datos de las Grandes Ligas en Baseball probablemente tiene una tabla llamada **Jugadores** (*Players*) (con la lista de todos los jugadores activos) y otra tabla llamada **Equipos** (*Teams*) (con la lista de todos los equipos activos). Ambas tablas están conectadas porque **un equipo tiene muchos jugadores, pero un jugador puede estar en un solo equipo.**

![SQL una a muchos](https://github.com/breatheco-de/content/blob/master/src/assets/images/374d53ac-092f-4f34-a6f1-76bfaa5bd676.png?raw=true)

**Muchos a muchos:**
#### Muchos a muchos:

Una base de datos de la biblioteca pública probablemente tenga una tabla llamada Autor (que contiene la información de todos los autores con libros publicados), y también otra tabla con TODOS los libros que se han publicado. Ambas tablas están relacionadas porque **un autor puede tener muchos libros y un libro puede tener muchos autores.**
Una base de datos de la biblioteca pública probablemente tenga una tabla llamada **Autor** (*Author*) (que contiene la información de todos los autores con libros publicados), y también otra tabla con TODOS los **Libros** (*Books*) que se han publicado. Ambas tablas están relacionadas porque **un autor puede tener muchos libros y un libro puede tener muchos autores.**

![SQL muchos a muchos](https://github.com/breatheco-de/content/blob/master/src/assets/images/af7344fc-0ee0-499e-8926-8f70dc9b2b0d.png?raw=true)

Expand All @@ -90,7 +90,7 @@ CREATE TABLE IF NOT EXISTS `chat_group` (
`chat_group_id` int(10) UNSIGNED NOT NULL,
`name` varchar(20) NOT NULL,
`create_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY('chat_group_id')
PRIMARY KEY(`chat_group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
```

Expand All @@ -112,7 +112,7 @@ DROP TABLE customers;

#### Manipulando datos

Cuando usamos SQL, existen 4 comandos principales para manipular datos: SELECT, INSERT, UPDATE y DELETE.
Cuando usamos SQL, existen 4 comandos principales para manipular datos: `SELECT`, `INSERT`, `UPDATE` y `DELETE`.

Todos esos comandos están diseñados para manipular UNO o VARIOS registros/filas de la base de datos al mismo tiempo. Pero, solo puedes ejecutar UN comando a la vez.

Expand All @@ -124,7 +124,9 @@ Esta es la operación más utilizada. Es la única forma de recuperar cualquier
SELECT column1, column2... columnN FROM table1 WHERE column1 = 3;

// Selecciona un usuario en particular por su número de seguridad social
SELECT ssn, username, email FROM USER WHERE ssn = '233-34-3453';
SELECT ssn, username, email
FROM user
WHERE ssn = '233-34-3453';
```

##### INSERT:
Expand All @@ -135,7 +137,8 @@ Crea una nueva fila/registro en la tabla. Se agregará al final.
INSERT INTO table_name (column1,column2,...columnN) VALUES (value1,value2,...valueN);

// Inserta un usuario nuevo
INSERT INTO USER (ssn,username,email) VALUES ('234-45-3342','alesanchezr','[email protected]');
INSERT INTO user (ssn, username, email)
VALUES ('234-45-3342', 'alesanchezr', '[email protected]');
```

##### UPDATE:
Expand All @@ -146,12 +149,14 @@ Actualiza un registro o una fila de una tabla específica. Es necesario proporci
UPDATE table_name SET column1 = value1 WHERE [condition]

// Actualiza el email de un usuario
UPDATE USER SET email = '[email protected]' WHERE ssn = '333-44-5534'
UPDATE user
SET email = '[email protected]'
WHERE ssn = '333-44-5534'
```

##### DELETE:

Funciona de manera muy similar a update, pero, en lugar de pasar los nuevos valores de las nuevas columnas que deseas actualizar, solo necesitamos especificar qué filas deseamos eliminar solicitando un grupo de condiciones.
Funciona de manera muy similar a UPDATE, pero, en lugar de pasar los nuevos valores de las nuevas columnas que deseas actualizar, solo necesitamos especificar qué filas deseamos eliminar solicitando un grupo de condiciones.

```sql
DELETE FROM table_name WHERE [condition]
Expand All @@ -160,7 +165,8 @@ DELETE FROM table_name WHERE [condition]
DELETE FROM user;

// Elimina un usuario en específico
DELETE FROM user WHERE ssn = '342-45-6732'
DELETE FROM user
WHERE ssn = '342-45-6732';
```

#### Integridad de los datos
Expand Down Expand Up @@ -236,7 +242,7 @@ SAVEPOINT savepoint_name;

Este comando solo sirve en la creación de un SAVEPOINT entre declaraciones transaccionales. El comando ROLLBACK se usa para deshacer un grupo de transacciones.

La sintaxis para volver a una SAVEPOINT es la siguiente:
La sintaxis para volver a un SAVEPOINT es la siguiente:

```sql
ROLLBACK TO savepoint_name;
Expand All @@ -260,4 +266,4 @@ La sintaxis para el comando es la siguiente:
SET TRANSACTION [ READ WRITE | READ ONLY ];
```

> 🔗 https://www.tutorialspoint.com/sql/sql-syntax.html
> 🔗 https://www.tutorialspoint.com/sql/sql-syntax.htm
44 changes: 25 additions & 19 deletions src/content/lesson/what-is-sql-database.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Mastering Databases: What is SQL Database"
subtitle: "Are you ready to work with data? Learn here about what is SQL Database and how to work with it."
subtitle: "Are you ready to work with data? Learn here about what SQL Database is, and how to work with it."
cover_local: "../../assets/images/e16d59ad-4c11-4ca0-8bfc-5a9d147c6c2e.jpeg"
textColor: "white"
date: "2023-06-26T00:35:31+00:00"
Expand All @@ -19,15 +19,15 @@ The SQL query syntax looks like this:
SELECT username FROM user WHERE email='[email protected]'
```

☝ In this example, we request from the database all users with the email address equal to "[email protected]".
☝ In this example, we request from the database all users with an email address equal to "[email protected]".

> If you want to earn the respect of a developer, you need to get comfortable with SQL. You will use it A LOT when working with data.

### Origins of SQL and Databases

In a world in which the presence of data is becoming more and more important due to its significant impact on decision making and the proliferation of business processes guided by data and information, databases are the best way to store them. In fact, a fundamental component of Industry 4.0 is precisely this technology. From data we will be able to carry out Data Mining, Machine Learning and automation processes, but everything starts from databases.
In a world in which the presence of data is becoming more and more important due to its significant impact on decision-making and the proliferation of business processes guided by data and information, databases are the best way to store them. In fact, a fundamental component of Industry 4.0 is precisely this technology. From data, we will be able to carry out Data Mining, Machine Learning and automation processes, but everything starts with databases.

The origin of databases was the `.txt` and `.csv` files, which, although they allowed storing a large amount of information, the data were easy to corrupt and difficult to access.
The origin of databases was the `.txt` and `.csv` files, which, although they allowed storing a large amount of information, it made the data easy to corrupt and difficult to access.

![Edgar Codd](https://github.com/breatheco-de/content/blob/master/src/assets/images/11fcd6d8-6177-4f42-b4e0-7b6475f24b0a.jpeg?raw=true)

Expand Down Expand Up @@ -57,29 +57,29 @@ A table can contain a large set of rows and columns. The access and query execut

A database is a collection of interconnected tables. The connection between two tables is called a "relationship" and can be one of the following:

**One to one:**
#### One to one:

The perfect example is the social security database, probably this database has a table called Taxpayer that contains all the information about each person with a social security number and another table with the current year's Tax Returns: **A person can have only one return and only one return can be made by a person.**
The perfect example is the social security database. Probably this database has a table called **TaxPayer** that contains all the information about each person with a social security number and another table with the current year's Tax Returns: **A person can have only one return, and only one return can be made by a person.**

![SQL one to one](https://github.com/breatheco-de/content/blob/master/src/assets/images/6f51ce02-3a75-4027-ada5-cf63c50d1701.png?raw=true)

**One to many:**
#### One to many:

The Major League Baseball database probably has a table called Players (with a list of all active players) and another table called Teams with a list of all active teams. Both tables are connected because **one team has many players, but a player can be on only one team.**
The Major League Baseball database probably has a table called **Players** (with a list of all active players) and another table called **Teams** (with a list of all active teams). Both tables are connected because **one team has many players, but a player can be on only one team.**

![SQL one to many](https://github.com/breatheco-de/content/blob/master/src/assets/images/374d53ac-092f-4f34-a6f1-76bfaa5bd676.png?raw=true)

**Many to many:**
#### Many to many:

A public library database probably has a table called Author (which contains the information of all authors with published books), and also another table with ALL books that have been published. Both tables are related because **one author can have many books and one book can have many authors.**
A public library database probably has a table called **Author** (which contains the information of all authors with published books), and also another table with ALL **Books** that have been published. Both tables are related because **one author can have many books, and one book can have many authors.**

![SQL many to many](https://github.com/breatheco-de/content/blob/master/src/assets/images/af7344fc-0ee0-499e-8926-8f70dc9b2b0d.png?raw=true)

### SQL syntax

#### Manipulating tables

There are 3 main operations that can be performed on a table: **create**, **update** or **delete**. In SQL, these operations are called `CREATE`, `ALTER` and `DROP`. Remember that these operations are used to manipulate the structure of the database, not the information it contains.
There are 3 main operations that can be performed on a table: **create**, **update**, or **delete**. In SQL, these operations are called `CREATE`, `ALTER` and `DROP`. Remember that these operations are used to manipulate the structure of the database, not the information it contains.

##### CREATE:

Expand All @@ -90,7 +90,7 @@ CREATE TABLE IF NOT EXISTS `chat_group` (
`chat_group_id` int(10) UNSIGNED NOT NULL,
`name` varchar(20) NOT NULL,
`create_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY('chat_group_id')
PRIMARY KEY(`chat_group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
```

Expand All @@ -112,7 +112,7 @@ DROP TABLE customers;

#### Manipulating data

When using SQL, there are 4 main commands for manipulating data: SELECT, INSERT, UPDATE and DELETE.
When using SQL, there are 4 main commands for manipulating data: `SELECT`, `INSERT`, `UPDATE` and `DELETE`.

All of these commands are designed to manipulate ONE or SEVERAL database records/rows at the same time. But, you can only execute ONE command at a time.

Expand All @@ -124,7 +124,9 @@ This is the most commonly used operation. It is the only way to retrieve any spe
SELECT column1, column2... columnN FROM table1 WHERE column1 = 3;

// Select a particular user by his Social Security Number
SELECT ssn, username, email FROM USER WHERE ssn = '233-34-3453';
SELECT ssn, username, email
FROM user
WHERE ssn = '233-34-3453';
```

##### INSERT:
Expand All @@ -135,7 +137,8 @@ Creates a new row/record in the table. It will be added at the end.
INSERT INTO table_name (column1,column2,...columnN) VALUES (value1,value2,...valueN);

// Insert a particular user
INSERT INTO USER (ssn,username,email) VALUES ('234-45-3342','alesanchezr','[email protected]');
INSERT INTO user (ssn, username, email)
VALUES ('234-45-3342', 'alesanchezr', '[email protected]');
```

##### UPDATE:
Expand All @@ -146,12 +149,14 @@ Updates a record or a row in a specific table. It is necessary to provide one or
UPDATE table_name SET column1 = value1 WHERE [condition]

// Updating the email of a user
UPDATE USER SET email = '[email protected]' WHERE ssn = '333-44-5534'
UPDATE user
SET email = '[email protected]'
WHERE ssn = '333-44-5534'
```

##### DELETE:

Works very similarly to update, but instead of passing the new values of the new columns you want to update, we only need to specify which rows we want to delete by requesting a set of conditions.
Works very similarly to UPDATE, but instead of passing the new values of the new columns you want to update, we only need to specify which rows we want to delete by requesting a set of conditions.

```sql
DELETE FROM table_name WHERE [condition]
Expand All @@ -160,7 +165,8 @@ DELETE FROM table_name WHERE [condition]
DELETE FROM user;

// Delete a specific user
DELETE FROM user WHERE ssn = '342-45-6732'
DELETE FROM user
WHERE ssn = '342-45-6732';
```

#### Data Integrity
Expand Down Expand Up @@ -194,7 +200,7 @@ Transaction control commands are only used with the DML INSERT, UPDATE and DELET

##### COMMIT statement

The `COMMIT` command is used to permanently save changes made to a transaction within the database. When you use INSERT, UPDATE or DELETE, the changes made with these commands are not permanent, the changes made can be undone or, in other words, we can go back.
The `COMMIT` command is used to permanently save changes made to a transaction within the database. When you use INSERT, UPDATE or DELETE, the changes made with these commands are not permanent; the changes made can be undone or, in other words, we can go back.

However, when you use the COMMIT command, the changes to your database will be permanent.

Expand Down
Loading