← Back to Constraints
Question 68
Announcements With Sensible Defaults
Announcements With Sensible Defaults
Create a table calledannouncementswith four columns:id(anINTEGER PRIMARY KEY),title(TEXT, required),is_pinned(INTEGER, required, defaulting to0) andaudience(TEXT, required, defaulting to'everyone'). An insert that gives only atitlemust be accepted and filled in with the defaults; an insert that explicitly setsis_pinnedto 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
Sign in to use hintsTopics:
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.