CJCoding With Joseph
15free / daySign inCreate account

Announcements With Sensible Defaults

Create a table called announcements with four columns: id (an INTEGER PRIMARY KEY), title (TEXT, required), is_pinned (INTEGER, required, defaulting to 0) and audience (TEXT, required, defaulting to 'everyone'). An insert that gives only a title must be accepted and filled in with the defaults; an insert that explicitly sets is_pinned to NULL must be rejected, because a default only applies when the column is left out.

Expected result:

Table announcements
✓ id INTEGER PRIMARY KEY
✓ title TEXT NOT NULL
✓ is_pinned INTEGER NOT NULL DEFAULT 0
✓ audience TEXT NOT NULL DEFAULT 'everyone'
✓ Insert an announcement giving only a title: accepted
✓ Insert an announcement with is_pinned set to NULL: rejected (NOT NULL)
Hints3 available
Topics:
Constraints
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (sel, ins, desc)

Results

Run your SQL to see every statement's output here, then how it compares with the expected answer.

Not sure what is in a table? SHOW TABLES lists them and DESCRIBE students shows the columns — or open the database browser on the left.