From 8369f01d994d84c63eae6fc6ece59ba46e3c83eb Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Sun, 29 Dec 2024 15:16:52 +0000 Subject: [PATCH] Add new challenges --- .../lessons/constraints-challenge.md | 40 +++++++++++++++++++ .../lessons/data-types-challenge.md | 31 ++++++++++++++ .../lessons/data-types-in-sqlite.md | 2 +- .../lessons/simple-table-creation.md | 27 +++++++++++++ .../lessons/table-creation.md | 32 --------------- src/styles/global.css | 15 ++++++- 6 files changed, 112 insertions(+), 35 deletions(-) create mode 100644 src/data/courses/sql/chapters/data-definition-language/lessons/constraints-challenge.md create mode 100644 src/data/courses/sql/chapters/data-definition-language/lessons/data-types-challenge.md create mode 100644 src/data/courses/sql/chapters/data-definition-language/lessons/simple-table-creation.md delete mode 100644 src/data/courses/sql/chapters/data-definition-language/lessons/table-creation.md diff --git a/src/data/courses/sql/chapters/data-definition-language/lessons/constraints-challenge.md b/src/data/courses/sql/chapters/data-definition-language/lessons/constraints-challenge.md new file mode 100644 index 000000000..614905e5b --- /dev/null +++ b/src/data/courses/sql/chapters/data-definition-language/lessons/constraints-challenge.md @@ -0,0 +1,40 @@ +--- +title: Constraints Challenge +description: Create a table for bookstore inventory using various SQL constraints +order: 320 +type: challenge +initSteps: [] +expectedResults: + - columns: [message] + values: + - ['Table created successfully'] +--- + +You need to create a table named `book_inventory` for a bookstore system. The table should track detailed information about books using appropriate data types and constraints listed below. + +| Column | Data Type | Constraints | +| ------------ | ---------------- | -------------------------------------------- | +| id | `INTEGER` | Primary Key | +| isbn | `VARCHAR(13)` | Null values not allowed and must be unique | +| title | `VARCHAR(200)` | Null values not allowed | +| author | `VARCHAR(100)` | Null values not allowed | +| price | `DECIMAL(10, 2)` | Null values not allowed and must be positive | +| pages | `INTEGER` | Must be positive | +| in_stock | `BOOLEAN` | Not null and default true | +| publish_year | `INTEGER` | Not null | +| last_updated | `TIMESTAMP` | Not null and default `CURRENT_TIMESTAMP` | + +## Expected Output + +After executing your query, the table should be created successfully with all specified columns and constraints. + +## Notes + +This challenge tests your knowledge of: + +- SQL data types (INTEGER, VARCHAR, DECIMAL, BOOLEAN, DATE, TIMESTAMP) +- Primary key and unique constraints +- NOT NULL constraints +- DEFAULT values +- CHECK constraints for data validation +- Working with date and time data types diff --git a/src/data/courses/sql/chapters/data-definition-language/lessons/data-types-challenge.md b/src/data/courses/sql/chapters/data-definition-language/lessons/data-types-challenge.md new file mode 100644 index 000000000..41e59e0bf --- /dev/null +++ b/src/data/courses/sql/chapters/data-definition-language/lessons/data-types-challenge.md @@ -0,0 +1,31 @@ +--- +title: Data Types Challenge +description: Create a table for bookstore inventory using appropriate SQL data types +order: 310 +type: challenge +initSteps: [] +expectedResults: + - columns: [message] + values: + - ['Table created successfully'] +--- + +You need to create a table named `book_inventory` for a bookstore system. The table should track detailed information about books using appropriate data types. + +| Column | Description | +| ---------------- | ---------------------------------------------- | +| id | Whole numbers for identification (Primary Key) | +| isbn | Text of exactly 13 characters | +| title | Variable-length text up to 200 characters | +| author | Variable-length text up to 100 characters | +| price | Number with 2 decimal places and precision 10 | +| pages | Whole number | +| in_stock | True/False value | +| publication_date | Date only (no time) | +| last_updated | Date and time together | + +The only constraint you need to implement is that the `id` column should be a primary key. Apart from that, you are only being tested on the data types. + +## Expected Output + +After executing your query, the table should be created successfully with all specified columns using appropriate data types. \ No newline at end of file diff --git a/src/data/courses/sql/chapters/data-definition-language/lessons/data-types-in-sqlite.md b/src/data/courses/sql/chapters/data-definition-language/lessons/data-types-in-sqlite.md index aa146b351..4fb89735e 100644 --- a/src/data/courses/sql/chapters/data-definition-language/lessons/data-types-in-sqlite.md +++ b/src/data/courses/sql/chapters/data-definition-language/lessons/data-types-in-sqlite.md @@ -50,7 +50,7 @@ The output will be: | --- | -------- | ----------- | | 1 | John Doe | Twenty Five | -You should also note that SQLite supports only a few data types: `INTEGER`, `REAL`, `TEXT`, `BLOB`, and `NULL`. Other data types such as `DECIMAL`, `FLOAT`, `VARCHAR`, etc., are not supported, although it will not complain if you try to assign them to a column. +You should also note that SQLite supports only a few data types: `INTEGER`, `REAL`, `TEXT`, `BLOB`, and `NULL`. Other data types such as  `DECIMAL`, `FLOAT`, `VARCHAR`, etc., are not supported, although it will not complain if you try to assign them to a column. For more details, check the [SQLite data types](https://www.sqlite.org/datatype3.html) and [why it uses dynamic typing](https://www.sqlite.org/flextypegood.html) in the official documentation. diff --git a/src/data/courses/sql/chapters/data-definition-language/lessons/simple-table-creation.md b/src/data/courses/sql/chapters/data-definition-language/lessons/simple-table-creation.md new file mode 100644 index 000000000..81f3ea25a --- /dev/null +++ b/src/data/courses/sql/chapters/data-definition-language/lessons/simple-table-creation.md @@ -0,0 +1,27 @@ +--- +title: Simple Table Creation +description: Write a SQL query to create a `books` table with specific columns. +order: 300 +type: challenge +initSteps: [] +expectedResults: + - columns: [message] + values: + - ['Table created successfully'] +--- + +You are required to create a table named `books` for a bookstore database. The table should have the following columns: + +| Column Name | Data Type | +| -------------- | -------------- | +| id | `INTEGER` | +| title | `VARCHAR(250)` | +| author | `VARCHAR(250)` | +| genre | `VARCHAR(250)` | +| published_date | `DATE` | + +Create a simple table with these columns using basic data types. + +## Expected Output + +After executing the query, there should be no errors and the table should be created successfully. You can verify the schema under the `Schema` tab. diff --git a/src/data/courses/sql/chapters/data-definition-language/lessons/table-creation.md b/src/data/courses/sql/chapters/data-definition-language/lessons/table-creation.md deleted file mode 100644 index fa46103e4..000000000 --- a/src/data/courses/sql/chapters/data-definition-language/lessons/table-creation.md +++ /dev/null @@ -1,32 +0,0 @@ ---- -title: Table Creation -description: Write a SQL query to create a `books` table with specific columns. -order: 300 -type: challenge -initSteps: [] -expectedResults: - - columns: [message] - values: - - ['Table created successfully'] ---- - -You are required to create a table named `books` for a bookstore database. The table should have the following columns: - -| Column Name | Data Type | Constraints | -| -------------- | -------------- | ----------------- | -| id | INTEGER | PRIMARY KEY | -| title | VARCHAR(250) | NOT NULL | -| author | VARCHAR(250) | NOT NULL | -| genre | VARCHAR(250) | | -| price | DECIMAL(10, 2) | CHECK (price > 0) | -| published_date | DATE | | - -Table should have following constraints in place: - -- The `id` column should uniquely identify each book. -- The `title` and `author` columns cannot be `NULL`. -- The `price` column must be greater than `0`. - -## Expected Output - -After executing the query, there should be no errors and the table should be created successfully. diff --git a/src/styles/global.css b/src/styles/global.css index 652462aef..ff9812c06 100644 --- a/src/styles/global.css +++ b/src/styles/global.css @@ -59,6 +59,14 @@ p > code:before, .prose ol li > code:before, p > code:before, .prose ol li > code:after, +.course-content h1 > code:after, +.course-content h1 > code:before, +.course-content h2 > code:after, +.course-content h2 > code:before, +.course-content h3 > code:after, +.course-content h3 > code:before, +.course-content h4 > code:after, +.course-content h4 > code:before, p > code:after, a > code:after, a > code:before { @@ -73,13 +81,16 @@ a > code:before { .course-content em > code, .course-content h1 > code, .course-content h2 > code, -.course-content h3 > code { +.course-content h3 > code, +.course-content table code { background: #f4f4f5 !important; border: 1px solid #282a36 !important; color: #282a36 !important; padding: 2px 4px; border-radius: 5px; - font-size: 17px !important; + font-size: 16px !important; + white-space: pre; + font-weight: normal; } .course-content.prose blockquote h1,