Create an Account Notes Table
Create account_notes with note_id, account_id, note_text, and created_at.
- Table creation
- Keys and constraints
Exercise brief
Understand the request
Support platform team Account notes require a stable identifier, a valid account relationship, the note text, and its business date.
Support teams need a governed place to attach dated notes to customer accounts.
Return
- Create four columns with the requested keys, types, and nullability.
Constraints
- Make note_id the primary key.
- Reference accounts(account_id).
- Make account_id, note_text, and created_at required.
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
accounts
account_idINTEGER
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
Define the table and its integrity rules together with CREATE TABLE.
Hint 2
Use PRIMARY KEY for note_id and REFERENCES accounts(account_id) for the relationship.
Hint 3
CREATE TABLE account_notes (note_id INTEGER PRIMARY KEY, account_id INTEGER NOT NULL REFERENCES accounts(account_id), ...);
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
CREATE TABLE account_notes (
note_id INTEGER PRIMARY KEY,
account_id INTEGER NOT NULL REFERENCES accounts(account_id),
note_text VARCHAR(200) NOT NULL,
created_at DATE NOT NULL
);Why this works
Keys and NOT NULL constraints turn the business rules into database-enforced guarantees instead of application conventions.
Success check
The table has exactly four columns and a foreign key from account_id to accounts.
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Build the next SQL skill
WHERE Clause & Filtering
Practice SQL WHERE clauses with realistic boundary, NULL, text, date, exclusion, and production-filtering problems.
SQL Joins
Practice reliable INNER, LEFT, FULL, CROSS, self, semi, anti, range, temporal, and many-to-many join patterns.
Basic SQL Functions
Practice production-oriented string cleanup, numeric transformations, NULL handling, tolerant conversion, and delimiter parsing.
Open the interactive workspace and practice across SQL topics.