|
2 | 2 |
|
3 | 3 | SQL (Structured Query Language) is a programming language used for managing the data that is stored in a DBMS (DataBase Management System). The `Query` part in SQL refers to the act of "asking a database" for a certain type of information; you are `querying the database`. |
4 | 4 |
|
5 | | -There are several implementations (software) of DBMS. Each software provides its own query language. For this course, you will learn [MySQL](https://www.mysql.com/). |
| 5 | +There are several implementations (software) of DBMS. Each software provides its own query language. For this course, you will learn [PostgreSQL](https://www.postgresql.org/). |
6 | 6 |
|
7 | 7 | To learn more, check out the following: |
8 | 8 |
|
9 | 9 | {% hyf-youtube src="https://www.youtube.com/watch?v=kqUIoOM3WEs" %} |
10 | 10 |
|
11 | 11 | ## What are data types (as applied to databases)? |
12 | 12 |
|
13 | | -When you store data in MySQL, each datum (singular of the word data) needs to be associated with its type. |
| 13 | +When you store data in PostgreSQL, each datum (singular of the word data) needs to be associated with its type. |
14 | 14 |
|
15 | 15 | For example numbers like 42, 1636 or -345 are all associated with the type `int`. |
16 | 16 |
|
17 | | -The following is a list of the most frequently used data types. |
| 17 | +The following is a list of the most frequently used PostgreSQL data types. |
18 | 18 |
|
19 | | -| Type | Description | Example Value | |
20 | | -| ---------- | --------------------------------------------- | ------------------------- | |
21 | | -| int | Numbers | 42 | |
22 | | -| float | Decimal numbers | 3.14 | |
23 | | -| varchar(N) | String with variable maximum of N characters | "Dragon" | |
24 | | -| text | String with fixed maximum of 65535 characters | "Positive" | |
25 | | -| datetime | Store date and time without timezone | `2019-01-01 22:10:23` | |
26 | | -| timestamp | Store date with timezone (e.g. last login) | `2019-01-01 22:10:23 UTC` | |
27 | | -| BLOB | Store binary files | an image | |
| 19 | +| Type | Description | Example Value | |
| 20 | +| ------------- | --------------------------------------------- | ------------------------- | |
| 21 | +| INTEGER | Numbers | 42 | |
| 22 | +| REAL | Decimal numbers | 3.14 | |
| 23 | +| VARCHAR(N) | String with variable maximum of N characters | 'Dragon' | |
| 24 | +| TEXT | String with unlimited length | 'Positive' | |
| 25 | +| TIMESTAMP | Store date and time without timezone | `2019-01-01 22:10:23` | |
| 26 | +| TIMESTAMPTZ | Store date with timezone (e.g. last login) | `2019-01-01 22:10:23+00` | |
| 27 | +| BYTEA | Store binary data | an image | |
28 | 28 |
|
29 | | -There are many more data types. You can read about them [here](https://www.w3resource.com/mysql/mysql-data-types.php). |
| 29 | +There are many more data types. You can read about them [here](https://www.postgresql.org/docs/current/datatype.html). |
30 | 30 |
|
31 | 31 | For a video explanation of the above table have a look at: |
32 | 32 |
|
33 | | -{% hyf-youtube src="https://www.youtube.com/watch?v=PT2GXYs9FEY" %} |
| 33 | +{% hyf-youtube src="https://www.youtube.com/watch?v=HnnPgdL0snI" %} |
34 | 34 |
|
35 | 35 | ## How to use SQL to Create, Read, Update and Delete (CRUD) |
36 | 36 |
|
37 | | -With the knowledge of all the datatypes, you can now create tables that contain the data with these datatypes. |
| 37 | +With the knowledge of all the data types, you can now create tables that contain the data with these data types. |
38 | 38 |
|
39 | | -Tables contain columns and columns have datatypes. For example, in a column with names of students, you cannot have numbers. |
| 39 | +Tables contain columns and columns have data types. For example, in a column with names of students, you cannot have numbers. |
40 | 40 |
|
41 | | -- MySQL provides a `CREATE TABLE` statement that creates a table with columns. You can choose the table name, column names but you have to choose the pre-defined datatypes supported by MySQL. For example, a column `Registration number` cannot have the data type number. It must use `int` because it represents the numeric datatype. |
| 41 | +- SQL provides a `CREATE TABLE` statement that creates a table with columns. You can choose the table name, column names but you have to choose the pre-defined data types supported by PostgreSQL. For example, a column `Registration number` cannot have the data type number. It must use `INTEGER` because it represents the numeric datatype. |
42 | 42 |
|
43 | | -- MySQL provides `SELECT` statement which reads (columns and rows) from a table with or without filtration. |
| 43 | +- SQL provides `SELECT` statement which reads (columns and rows) from a table with or without filtration. |
44 | 44 |
|
45 | | -- MySQL provides `UPDATE` statement which changes the contents of (columns and rows of) a table. |
| 45 | +- SQL provides `UPDATE` statement which changes the contents of (columns and rows of) a table. |
46 | 46 |
|
47 | | -- MySQL provides `DELETE` statement which can delete rows of tables. In order to delete columns, you need to use `ALTER` and `DROP` statements. |
| 47 | +- SQL provides `DELETE` statement which can delete rows of tables. In order to delete columns, you need to use `ALTER` and `DROP` statements. |
48 | 48 |
|
49 | 49 | Check out the following to learn more about how to apply SQL: |
50 | 50 |
|
|
0 commit comments