Prepare SQL statements while testing them on a local running database.
Write all of your SQL statements in todo_app.sql
- Write a query to delete a user named
michael
if it exists - Write a query to create a user named
michael
with an encrypted passwordstonebreaker
- Write a query to drop a database named
todo_app
if it exists - Write a query to create a database named
todo_app
- Connect to the newly created database
- Write a query to create a table named
tasks
using the Initial columns detailed below - Define column
id
as the table's primary key - Write queries to accomplish the following
- remove the column named
completed
- add a column to
tasks
namedcompleted_at
:timestamp, that may be NULL, and has a default value ofNULL
. - change the
updated_at
column to not allow NULL values, and have a default value ofnow()
- create a new task, by only setting values (not defining which columns)
id = default value
title = 'Study SQL'
description = 'Complete this exercise'
created_at = now()
updated_at = now()
completed_at = NULL
- create a new task
title = 'Study PostgreSQL'
description = 'Read all the documentation'
- select all the titles of tasks that are not yet completed
- update the task with a title of
'Study SQL'
to be completed as of now - select all titles and descriptions of tasks that are not yet completed
- select all fields of every task sorted by creation date in descending order
- create a new task
title = 'mistake 1'
description = 'a test entry'
- create a new task
title = 'mistake 2'
description = 'another test entry'
- create a new task
title = 'third mistake'
description = 'another test entry'
- select title fields of all tasks with a title that includes the word
'mistake'
- delete the task that has a title of
mistake 1
- select title and description fields of all tasks with a title that includes the word
'mistake'
- delete all tasks that includes the word
'mistake'
in the title - select all fields of all tasks sorted by
title
in ascending order
Column Name | Datatype | NULL | Default |
---|---|---|---|
id | integer | false | auto incrementing |
title | character varying (255) | false | |
description | text | true | |
created_at | timestamp (no tz) | false | now() |
updated_at | timestamp (no tz) | true | |
completed | boolean | false | false |
Column Name | Datatype | NULL | Default |
---|---|---|---|
id | integer | false | auto incrementing |
title | character varying (255) | false | |
description | text | true | |
created_at | timestamp (no tz) | false | now() |
updated_at | timestamp (no tz) | false | now() |
completed_at | timestamp (no tz) | true | NULL |