CJCoding With Joseph
15free / daySign inCreate account

Link Labs to Departments

Create labs with id INTEGER PRIMARY KEY, name TEXT NOT NULL and department_id INTEGER NOT NULL that REFERENCES departments(id). The foreign key means a lab can only belong to a department that exists: department 1 is accepted, department 99 is refused, and a lab with no department at all is refused by the NOT NULL rule.

Expected result:

Table labs
✓ id INTEGER PRIMARY KEY
✓ name TEXT NOT NULL
✓ department_id INTEGER NOT NULL
✓ department_id REFERENCES departments(id)
✓ A lab in department 99: rejected (FOREIGN KEY)
✓ A lab in Computer Science (department 1): accepted
✓ A lab with no department: rejected (NOT NULL)
Hints3 available
Topics:
CREATE TABLE
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.