← Back to ALTER & DROP
Question 20
Add a Required Column
Add a Required Column
Courses need a flag saying whether they run online. Addis_onlinetocoursesas anINTEGERcolumn that isNOT NULLwithDEFAULT 0. SQLite refuses to add aNOT NULLcolumn without a default, because the 14 existing rows would have nothing to put in it, so the default is what makes this possible.
Expected result:
Table courses ✓ id INTEGER PRIMARY KEY ✓ code TEXT NOT NULL ✓ title TEXT NOT NULL ✓ department_id INTEGER NOT NULL ✓ instructor_id INTEGER ✓ credits INTEGER NOT NULL DEFAULT 3 ✓ level INTEGER NOT NULL ✓ max_seats INTEGER ✓ room TEXT ✓ semester TEXT ✓ fee REAL ✓ is_online INTEGER NOT NULL DEFAULT 0 ✓ instructor_id REFERENCES instructors(id) ✓ department_id REFERENCES departments(id) ✓ UNIQUE (code)
Hints3 available
Sign in to use hintsTopics:
ALTER & DROP
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.