← Back to ALTER & DROP
Question 19
Add a Column With a Default
Add a Column With a Default
Track how many credits each student has earned so far. Add a columncredits_earnedof typeINTEGERwithDEFAULT 0tostudents. Existing rows get 0 straight away, and any futureINSERTthat leaves the column out also gets 0.
Expected result:
Table students ✓ id INTEGER PRIMARY KEY ✓ first_name TEXT NOT NULL ✓ last_name TEXT NOT NULL ✓ email TEXT NOT NULL ✓ major_department_id INTEGER ✓ enrollment_year INTEGER NOT NULL ✓ gpa REAL ✓ city TEXT ✓ birth_date TEXT ✓ status TEXT NOT NULL DEFAULT 'active' ✓ scholarship_amount REAL ✓ credits_earned INTEGER DEFAULT 0 ✓ major_department_id REFERENCES departments(id) ✓ UNIQUE (email)
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.