SQL for Backend Engineers · SQL problem
Create the Accounts Table
A free sql problem from the Keys, Constraints and Data Integrity skill. Read it here, then solve it in the app.
- Easy
- SQL problem
- Free
The problem
The signup service is moving from a spreadsheet to Postgres. Write the CREATE TABLE (and anything
else it needs) for accounts, so the database itself enforces these rules:
| column | rules |
|---|---|
id | the primary key, generated by the database |
email | required, and unique ignoring case - Ava@Example.com and ava@example.com are the same account |
plan | required, and must be the code of a row in plans |
seats | an int, at least 1, and 1 when an insert doesn't give it |
created_at | a timestamptz, required, and the current time when an insert doesn't give it |
plans already exists. The grader then tries a series of inserts - each undone before the next - and
reports whether each was accepted or rejected, and what a new account's defaults look like.
Constraints
Plans are added and retired over time - the list in plans is the source of truth, and it differs between environments.
How it's graded
- Your SQL runs on PostgreSQL 18. Run compares your rows with the expected rows on the sample data; Submit runs it against hidden datasets built to catch the classic mistakes.
- Stuck? Hints come in four steps, from a nudge to a code skeleton, each costing part of the points.
More problems in Keys, Constraints and Data Integrity
Write the query Create the Accounts Table free
No card needed. Lessons, practice questions and easy problems are free forever.
Free plan, no card · 7-day Pro trial · Cancel anytime