From 8a00da216c7aa88a318c045a82ef05efb4fd1057 Mon Sep 17 00:00:00 2001 From: Alex Manchester Date: Wed, 2 Apr 2025 10:57:36 -0700 Subject: [PATCH 1/4] simplified data type table --- episodes/00-sql-introduction.md | 44 ++++++--------------------------- 1 file changed, 7 insertions(+), 37 deletions(-) diff --git a/episodes/00-sql-introduction.md b/episodes/00-sql-introduction.md index d8092898..af1be0b5 100644 --- a/episodes/00-sql-introduction.md +++ b/episodes/00-sql-introduction.md @@ -235,46 +235,16 @@ You can also use this same approach to append new fields to an existing table. ### Data types {#datatypes} +SQLite has four data types, shown in the table below. + | Data type | Description | | ----------------------------------------------------- | :------------------------------------------------------------------------------------------------------- | -| CHARACTER(n) | Character string. Fixed-length n | -| VARCHAR(n) or CHARACTER VARYING(n) | Character string. Variable length. Maximum length n | -| BINARY(n) | Binary string. Fixed-length n | -| BOOLEAN | Stores TRUE or FALSE values | -| VARBINARY(n) or BINARY VARYING(n) | Binary string. Variable length. Maximum length n | -| INTEGER(p) | Integer numerical (no decimal). | -| SMALLINT | Integer numerical (no decimal). | -| INTEGER | Integer numerical (no decimal). | -| BIGINT | Integer numerical (no decimal). | -| DECIMAL(p,s) | Exact numerical, precision p, scale s. | -| NUMERIC(p,s) | Exact numerical, precision p, scale s. (Same as DECIMAL) | -| FLOAT(p) | Approximate numerical, mantissa precision p. A floating number in base 10 exponential notation. | +| TEXT | Character string | +| BLOB | Raw binary data | +| INTEGER | Integer numerical (signed positive or negative) | | REAL | Approximate numerical | -| FLOAT | Approximate numerical | -| DOUBLE PRECISION | Approximate numerical | -| DATE | Stores year, month, and day values | -| TIME | Stores hour, minute, and second values | -| TIMESTAMP | Stores year, month, day, hour, minute, and second values | -| INTERVAL | Composed of a number of integer fields, representing a period of time, depending on the type of interval | -| ARRAY | A set-length and ordered collection of elements | -| MULTISET | A variable-length and unordered collection of elements | -| XML | Stores XML data | - -### SQL Data Type Quick Reference {#datatypediffs} - -Different databases offer different choices for the data type definition. - -The following table shows some of the common names of data types between the various database platforms: - -| Data type | Access | SQLServer | Oracle | MySQL | PostgreSQL | -| :---------------------------------------------------- | :------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------- | :--------------- | :------------ | :------------ | -| boolean | Yes/No | Bit | Byte | N/A | Boolean | -| integer | Number (integer) | Int | Number | Int / Integer | Int / Integer | -| float | Number (single) | Float / Real | Number | Float | Numeric | -| currency | Currency | Money | N/A | N/A | Money | -| string (fixed) | N/A | Char | Char | Char | Char | -| string (variable) | Text (\<256) / Memo (65k+) | Varchar | Varchar2 | Varchar | Varchar | -| binary object OLE Object Memo Binary (fixed up to 8K) | Varbinary (\<8K) | Image (\<2GB) Long | Raw Blob | Text Binary | Varbinary | + +In addition to these four data types, SQLite has a NULL value for missing data. We will talk more about dealing with missing data in Episode 3. :::::::::::::::::::::::::::::::::::::::: keypoints From a5ce09a8bbe0f23d92b17dffac0f009a199394c8 Mon Sep 17 00:00:00 2001 From: Alex Manchester Date: Wed, 2 Apr 2025 14:22:00 -0700 Subject: [PATCH 2/4] improve descriptions in epsiode 1 data types table, added data type quick reference table to cheat sheet --- episodes/00-sql-introduction.md | 12 ++++++------ learners/sql-cheat-sheet.md | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/episodes/00-sql-introduction.md b/episodes/00-sql-introduction.md index af1be0b5..53cdcadf 100644 --- a/episodes/00-sql-introduction.md +++ b/episodes/00-sql-introduction.md @@ -237,12 +237,12 @@ You can also use this same approach to append new fields to an existing table. SQLite has four data types, shown in the table below. -| Data type | Description | -| ----------------------------------------------------- | :------------------------------------------------------------------------------------------------------- | -| TEXT | Character string | -| BLOB | Raw binary data | -| INTEGER | Integer numerical (signed positive or negative) | -| REAL | Approximate numerical | +| Data type | Description | +| ----------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------- | +| TEXT | Text string | +| INTEGER | Integer numerical (signed positive or negative) | +| REAL | Approximate numerical | +| BLOB | Multipurpose datatype with limited functionality that is generally used for data which does not fit into any of the other three categories | In addition to these four data types, SQLite has a NULL value for missing data. We will talk more about dealing with missing data in Episode 3. diff --git a/learners/sql-cheat-sheet.md b/learners/sql-cheat-sheet.md index 91f48fa8..33b7ec93 100644 --- a/learners/sql-cheat-sheet.md +++ b/learners/sql-cheat-sheet.md @@ -41,6 +41,22 @@ Sort results using `ASC` for ascending order or `DESC` for descending order: SELECT * FROM table_name ORDER BY column_name_1 ASC, column_name_2 DESC; +Data Types +---------- + +Different databases offer different choices for the data type definition. + +The following table shows some of the common names of data types between the various database platforms: + +| Data type | Access | SQLServer | Oracle | MySQL | PostgreSQL | SQLite | +| :---------------------------------------------------- | :------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------- | :--------------- | :------------ | :------------ | :------ | +| boolean | Yes/No | Bit | Byte | N/A | Boolean | Integer | +| integer | Number (integer) | Int | Number | Int / Integer | Int / Integer | Integer | +| float | Number (single) | Float / Real | Number | Float | Numeric | Real | +| currency | Currency | Money | N/A | N/A | Money | Real | +| string (fixed) | N/A | Char | Char | Char | Char | Text | +| string (variable) | Text (\<256) / Memo (65k+) | Varchar | Varchar2 | Varchar | Varchar | Text | +| binary object OLE Object Memo Binary (fixed up to 8K) | Varbinary (\<8K) | Image (\<2GB) Long | Raw Blob | Text Binary | Varbinary | Blob | Missing Data ------------ From 82d4618e567c0a60a86f1ab4d8d57c718bab77a2 Mon Sep 17 00:00:00 2001 From: James Foster Date: Mon, 23 Mar 2026 18:06:59 +1100 Subject: [PATCH 3/4] Validation and clean-up --- episodes/00-sql-introduction.md | 44 ++++++++++++------------ learners/sql-cheat-sheet.md | 59 ++++++++++++++++++++++++--------- 2 files changed, 65 insertions(+), 38 deletions(-) diff --git a/episodes/00-sql-introduction.md b/episodes/00-sql-introduction.md index 53cdcadf..fadfb591 100644 --- a/episodes/00-sql-introduction.md +++ b/episodes/00-sql-introduction.md @@ -201,28 +201,28 @@ follow these instructions: 10. In the center panel of the window that appears, set the data types for each field using the suggestions in the table below (this includes fields from the `plots` and `species` tables also). 11. Finally, click **OK** one more time to confirm the operation. Then click the **Write Changes** button to save the database. -| Field | Data Type | Motivation | Table(s) | -| ----------------------------------------------------- | :------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- | ---------------- | -| day | INTEGER | Having data as numeric allows for meaningful arithmetic and comparisons | surveys | -| genus | TEXT | Field contains text data | species | -| hindfoot\_length | REAL | Field contains measured numeric data | surveys | -| month | INTEGER | Having data as numeric allows for meaningful arithmetic and comparisons | surveys | -| plot\_id | INTEGER | Field contains numeric data | plots, surveys | -| plot\_type | TEXT | Field contains text data | plots | -| record\_id | INTEGER | Field contains numeric data | surveys | -| sex | TEXT | Field contains text data | surveys | -| species\_id | TEXT | Field contains text data | species, surveys | -| species | TEXT | Field contains text data | species | -| taxa | TEXT | Field contains text data | species | -| weight | REAL | Field contains measured numerical data | surveys | -| year | INTEGER | Allows for meaningful arithmetic and comparisons | surveys | +| Field | Data Type | Motivation | Table(s) | +| ----------------------------------------------------- | :----------------------- | ----------------------------------------------------------------------- | ---------------- | +| day | INTEGER | Having data as numeric allows for meaningful arithmetic and comparisons | surveys | +| genus | TEXT | Field contains text data | species | +| hindfoot\_length | REAL | Field contains measured numeric data | surveys | +| month | INTEGER | Having data as numeric allows for meaningful arithmetic and comparisons | surveys | +| plot\_id | INTEGER | Field contains numeric data | plots, surveys | +| plot\_type | TEXT | Field contains text data | plots | +| record\_id | INTEGER | Field contains numeric data | surveys | +| sex | TEXT | Field contains text data | surveys | +| species\_id | TEXT | Field contains text data | species, surveys | +| species | TEXT | Field contains text data | species | +| taxa | TEXT | Field contains text data | species | +| weight | REAL | Field contains measured numerical data | surveys | +| year | INTEGER | Allows for meaningful arithmetic and comparisons | surveys | ::::::::::::::::::::::::::::::::::::::: challenge ### Challenge - Import the `plots` and `species` tables - + :::::::::::::::::::::::::::::::::::::::::::::::::: @@ -237,12 +237,12 @@ You can also use this same approach to append new fields to an existing table. SQLite has four data types, shown in the table below. -| Data type | Description | -| ----------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------- | -| TEXT | Text string | -| INTEGER | Integer numerical (signed positive or negative) | -| REAL | Approximate numerical | -| BLOB | Multipurpose datatype with limited functionality that is generally used for data which does not fit into any of the other three categories | +| Data type | Description | +| ------------------ | :-------------------------------------------------------------------------------------------------------------------- | +| TEXT | Text string | +| INTEGER | Integer (positive or negative whole number) | +| REAL | Approximate numerical value (floating point number) | +| BLOB | General data with no specfic type stored in the database exactly as given (stands for _Binary Large OBject_) | In addition to these four data types, SQLite has a NULL value for missing data. We will talk more about dealing with missing data in Episode 3. diff --git a/learners/sql-cheat-sheet.md b/learners/sql-cheat-sheet.md index 33b7ec93..fa3ff1da 100644 --- a/learners/sql-cheat-sheet.md +++ b/learners/sql-cheat-sheet.md @@ -41,22 +41,49 @@ Sort results using `ASC` for ascending order or `DESC` for descending order: SELECT * FROM table_name ORDER BY column_name_1 ASC, column_name_2 DESC; -Data Types ----------- - -Different databases offer different choices for the data type definition. - -The following table shows some of the common names of data types between the various database platforms: - -| Data type | Access | SQLServer | Oracle | MySQL | PostgreSQL | SQLite | -| :---------------------------------------------------- | :------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------- | :--------------- | :------------ | :------------ | :------ | -| boolean | Yes/No | Bit | Byte | N/A | Boolean | Integer | -| integer | Number (integer) | Int | Number | Int / Integer | Int / Integer | Integer | -| float | Number (single) | Float / Real | Number | Float | Numeric | Real | -| currency | Currency | Money | N/A | N/A | Money | Real | -| string (fixed) | N/A | Char | Char | Char | Char | Text | -| string (variable) | Text (\<256) / Memo (65k+) | Varchar | Varchar2 | Varchar | Varchar | Text | -| binary object OLE Object Memo Binary (fixed up to 8K) | Varbinary (\<8K) | Image (\<2GB) Long | Raw Blob | Text Binary | Varbinary | Blob | +Data Types across Database Platforms +------------------------------------ + +Different database systems use different names for data types. Please refer to the documentation of your specific database software. + +| Data type | Description | +| ----------------------------------------------------- | :------------------------------------------------------------------------------------------------------- | +| CHAR(n) | Character string. Fixed-length n | +| VARCHAR(n) or CHARACTER VARYING(n) | Character string. Variable length. Maximum length n | +| BINARY(n) | Binary string. Fixed-length n | +| BOOLEAN | Stores TRUE or FALSE values | +| VARBINARY(n) or BINARY VARYING(n) | Binary string. Variable length. Maximum length n | +| INTEGER(p) | Integer numerical (no decimal). | +| SMALLINT | Integer numerical (no decimal). | +| INTEGER | Integer numerical (no decimal). | +| BIGINT | Integer numerical (no decimal). | +| DECIMAL(p,s) | Exact numerical, precision p, scale s. | +| NUMERIC(p,s) | Exact numerical, precision p, scale s. (Same as DECIMAL) | +| FLOAT(p) | Approximate numerical, mantissa precision p. A floating number in base 10 exponential notation. | +| REAL | Approximate numerical | +| FLOAT | Approximate numerical | +| DOUBLE PRECISION | Approximate numerical | +| DATE | Stores year, month, and day values | +| TIME | Stores hour, minute, and second values | +| DATETIME or TIMESTAMP | Stores year, month, day, hour, minute, and second values | +| INTERVAL | Composed of a number of integer fields, representing a period of time, depending on the type of interval | +| ARRAY | A set-length and ordered collection of elements | +| MULTISET | A variable-length and unordered collection of elements | +| XML | Stores XML data | + +The following table shows some of the common names of data types used with various database platforms: + +| Data type | SQLite | Access | SQLServer | Oracle | MySQL | PostgreSQL | +| :-------------------| :-------| :----------------------------- | :---------------------------- | :--------------- | :------------ | :-------------| +| boolean | INTEGER | YES/NO | BIT | BYTE | N/A | BOOLEAN | +| integer | INTEGER | NUMBER (Integer) | INT | NUMBER | INT / INTEGER | INTEGER | +| float | REAL | NUMBER (Single / Double) | FLOAT / REAL | NUMBER | FLOAT | NUMERIC /REAL | +| currency | REAL | CURRENCY | MONEY | N/A | N/A | MONEY | +| string (fixed) | TEXT | N/A | CHAR | CHAR | CHAR | CHAR | +| string (variable) | TEXT | TEXT (\<256) / LONG TEXT (65+) | VARCHAR | VARCHAR2 | VARCHAR | VARCHAR | +| binary data | BLOB | BINARY / VARBINARY (\<8K) | IMAGE (\<2GB) | RAW / BLOB | BLOB / BINARY | BYTEA | + +Binary data is data with no specfic type (BLOB stands for _Binary Large OBject_) and is typically stored in the database exactly as given by the user. Missing Data ------------ From 9b7acc5465b5471c29151c9bf31bc0e027fd4535 Mon Sep 17 00:00:00 2001 From: James Foster Date: Tue, 24 Mar 2026 17:33:42 +1100 Subject: [PATCH 4/4] Final fixes with references --- episodes/00-sql-introduction.md | 2 +- learners/sql-cheat-sheet.md | 41 +++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/episodes/00-sql-introduction.md b/episodes/00-sql-introduction.md index fadfb591..0cb6b901 100644 --- a/episodes/00-sql-introduction.md +++ b/episodes/00-sql-introduction.md @@ -242,7 +242,7 @@ SQLite has four data types, shown in the table below. | TEXT | Text string | | INTEGER | Integer (positive or negative whole number) | | REAL | Approximate numerical value (floating point number) | -| BLOB | General data with no specfic type stored in the database exactly as given (stands for _Binary Large OBject_) | +| BLOB | General data with no specfic type, stored in the database exactly as given (stands for _Binary Large OBject_) | In addition to these four data types, SQLite has a NULL value for missing data. We will talk more about dealing with missing data in Episode 3. diff --git a/learners/sql-cheat-sheet.md b/learners/sql-cheat-sheet.md index fa3ff1da..92a7b47d 100644 --- a/learners/sql-cheat-sheet.md +++ b/learners/sql-cheat-sheet.md @@ -48,20 +48,19 @@ Different database systems use different names for data types. Please refer to t | Data type | Description | | ----------------------------------------------------- | :------------------------------------------------------------------------------------------------------- | -| CHAR(n) | Character string. Fixed-length n | +| CHARACTER(n) or CHAR(n) | Character string. Fixed-length n | | VARCHAR(n) or CHARACTER VARYING(n) | Character string. Variable length. Maximum length n | | BINARY(n) | Binary string. Fixed-length n | | BOOLEAN | Stores TRUE or FALSE values | | VARBINARY(n) or BINARY VARYING(n) | Binary string. Variable length. Maximum length n | -| INTEGER(p) | Integer numerical (no decimal). | -| SMALLINT | Integer numerical (no decimal). | -| INTEGER | Integer numerical (no decimal). | -| BIGINT | Integer numerical (no decimal). | -| DECIMAL(p,s) | Exact numerical, precision p, scale s. | -| NUMERIC(p,s) | Exact numerical, precision p, scale s. (Same as DECIMAL) | -| FLOAT(p) | Approximate numerical, mantissa precision p. A floating number in base 10 exponential notation. | -| REAL | Approximate numerical | -| FLOAT | Approximate numerical | +| INTEGER | Integer numerical (no decimal) | +| SMALLINT | Integer numerical (no decimal) | +| INTEGER | Integer numerical (no decimal) | +| BIGINT | Integer numerical (no decimal) | +| NUMERIC(p,s) or DECIMAL(p,s) or NUMBER(p,s) | Exact numerical, precision p (significant digits), scale s (digits in the fraction part). | +| FLOAT(p) | Approximate numerical (a floating point number) with p mantissa precision bits | +| REAL | Approximate numerical, same as FLOAT(p) but p will depend on the database system | +| FLOAT | Approximate numerical, using the default value of p for the database system | | DOUBLE PRECISION | Approximate numerical | | DATE | Stores year, month, and day values | | TIME | Stores hour, minute, and second values | @@ -73,18 +72,26 @@ Different database systems use different names for data types. Please refer to t The following table shows some of the common names of data types used with various database platforms: -| Data type | SQLite | Access | SQLServer | Oracle | MySQL | PostgreSQL | +| Data type | SQLite | Access (not SQL) | SQLServer | Oracle | MySQL | PostgreSQL | | :-------------------| :-------| :----------------------------- | :---------------------------- | :--------------- | :------------ | :-------------| -| boolean | INTEGER | YES/NO | BIT | BYTE | N/A | BOOLEAN | -| integer | INTEGER | NUMBER (Integer) | INT | NUMBER | INT / INTEGER | INTEGER | -| float | REAL | NUMBER (Single / Double) | FLOAT / REAL | NUMBER | FLOAT | NUMERIC /REAL | -| currency | REAL | CURRENCY | MONEY | N/A | N/A | MONEY | +| boolean | INTEGER | Yes/No | BIT | INTEGER | INTEGER | BOOLEAN | +| integer | INTEGER | Number (Integer) | INT | NUMBER | INT / INTEGER | INTEGER | +| float | REAL | Number (Single / Double) | FLOAT / REAL | NUMBER | FLOAT | NUMERIC /REAL | +| currency | REAL | Currency | MONEY | N/A | N/A | MONEY | | string (fixed) | TEXT | N/A | CHAR | CHAR | CHAR | CHAR | -| string (variable) | TEXT | TEXT (\<256) / LONG TEXT (65+) | VARCHAR | VARCHAR2 | VARCHAR | VARCHAR | -| binary data | BLOB | BINARY / VARBINARY (\<8K) | IMAGE (\<2GB) | RAW / BLOB | BLOB / BINARY | BYTEA | +| string (variable) | TEXT | Short (\<255 char) / Long Text | VARCHAR | VARCHAR2 | VARCHAR | VARCHAR | +| binary data | BLOB | Attachment | BINARY / IMAGE (\<2GB) | RAW / BLOB | BLOB / BINARY | BYTEA | Binary data is data with no specfic type (BLOB stands for _Binary Large OBject_) and is typically stored in the database exactly as given by the user. +Further information can be found at these references: +- [SQLite](https://sqlite.org/datatype3.html) +- [SQLServer](https://learn.microsoft.com/en-us/sql/t-sql/data-types/data-types-transact-sql) +- [Oracle](https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlqr/Data-Types.html) +- [MySQL](https://dev.mysql.com/doc/refman/9.6/en/data-types.html) +- [PostgreSQL](https://www.postgresql.org/docs/current/datatype.html) + + Missing Data ------------