A tax form data model SQL schema stores extracted forms in four layers: a documents table per upload, a pages table, a forms table with one row per W-2, 1099 or 1098, and a fields table with one row per box. Money goes in NUMERIC columns, TINs in text, and repeated items like Box 12 codes in child tables.
Which tables does a tax form data model SQL schema need?
A tax form data model SQL schema needs four core tables: documents, pages, forms and form_fields. One documents row is one uploaded file. One pages row is one page of that file. One forms row is one tax form found inside it. One form_fields row is one box value read from that form.
The split follows how the data arrives. A person uploads one PDF, and that PDF can hold a W-2, two 1099-INTs and a 1098. The upload, the pages and the forms each have a different lifetime and a different owner, so each gets its own table.
- documents holds the file-level facts: the file name, the page count, when it arrived, and when its original should be deleted.
- pages holds one row per page, with the page number and the form it was assigned to. It lets a reviewer jump from a value back to the right page image.
- forms holds what is true for the whole form: the form type, the tax year, the page range, the issuer's name and TIN, and the review status.
- form_fields holds the boxes. Each row names the field, records the printed box label and stores the value in a typed column.
Here is illustrative Postgres DDL for that design. It is an example design for your own application, not Schema Tax's internal schema, and every name in it is a choice you can change.
-- Example design only. Not Schema Tax's internal schema.
CREATE TABLE documents (
document_id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
source_filename text NOT NULL,
page_count smallint NOT NULL CHECK (page_count > 0),
received_at timestamptz NOT NULL DEFAULT now(),
original_storage_key text, -- NULL once the original file is deleted
original_deleted_at timestamptz,
delete_after date -- when the extracted rows themselves go
);
CREATE TABLE forms (
form_id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
document_id bigint NOT NULL REFERENCES documents ON DELETE CASCADE,
form_type text NOT NULL CHECK (form_type IN
('W-2','1099-NEC','1099-MISC','1099-INT','1099-DIV',
'1099-B','1098','1040','K-1')),
tax_year smallint NOT NULL CHECK (tax_year BETWEEN 2000 AND 2100),
first_page smallint NOT NULL,
last_page smallint NOT NULL CHECK (last_page >= first_page),
issuer_name text,
issuer_tin text CHECK (issuer_tin ~ '^[0-9X]{2}-[0-9X]{3}[0-9]{4}$'), -- full or masked EIN
recipient_tin_last4 text CHECK (recipient_tin_last4 ~ '^[0-9]{4}$'),
review_status text NOT NULL DEFAULT 'pending'
CHECK (review_status IN ('pending','needs_review','approved')),
extra jsonb -- rarely queried boxes, kept as delivered
);
CREATE TABLE pages (
document_id bigint NOT NULL REFERENCES documents ON DELETE CASCADE,
page_number smallint NOT NULL CHECK (page_number > 0),
form_id bigint REFERENCES forms ON DELETE SET NULL,
PRIMARY KEY (document_id, page_number)
);
CREATE TABLE form_fields (
form_id bigint NOT NULL REFERENCES forms ON DELETE CASCADE,
field_name text NOT NULL, -- 'wages', 'mortgage_interest', ...
box text NOT NULL, -- '1', '12a', '14b'
value_amount numeric(14,2),
value_text text,
value_date date,
status text NOT NULL CHECK (status IN ('ok','blank','needs_review')),
PRIMARY KEY (form_id, field_name)
);
CREATE TABLE w2_box12_items (
form_id bigint NOT NULL REFERENCES forms ON DELETE CASCADE,
slot text NOT NULL CHECK (slot ~ '^12[a-d]$'),
code text NOT NULL CHECK (code ~ '^[A-Z]{1,2}$'),
amount numeric(14,2) NOT NULL,
PRIMARY KEY (form_id, slot)
);
CREATE INDEX forms_document_idx ON forms (document_id);
CREATE INDEX forms_year_type_idx ON forms (tax_year, form_type);
The envelope behind these columns (document ID, form type, tax year, page range) is the same one a JSON payload carries. Field naming, envelope design and schema versions are worked out in the guide to designing a tax form JSON schema, and this post takes those names as given.
Wide SQL tables per form or one generic tax field table?
Wide SQL tables give each form type its own table with one typed column per box. A generic tax field table stores every box as a row of field name, box and value. Most applications do best with a hybrid: shared form columns, a field table, and a JSONB column for rarely used boxes.
Wide tables read well. A query for W-2 wages is SELECT wages FROM w2s, and the database enforces a type on every box. The cost is the table count. Nine form types means nine tables, and every IRS revision that adds a box needs an ALTER TABLE. A query that sums federal withholding across W-2s, 1099-NECs and 1099-INTs becomes a UNION ALL over several tables.
A generic field table is the opposite trade. One table holds every box of every form, so a new box is a new row, not a migration. Cross-form questions become one query filtered on field_name. The cost is weaker typing: a single value column cannot be both money and a date. The DDL above handles that with three typed value columns, value_amount, value_text and value_date, and only one is filled for any row.
The hybrid keeps the best of both. Facts every form shares live as real columns on forms. The boxes you query, total and review live as rows in form_fields. Boxes you only need to show back to a user, such as a 1098's free-text "Other" box, can sit in the extra jsonb column. The PostgreSQL 18 documentation on JSON types says "most applications should prefer to store JSON data as jsonb", that jsonb is "significantly faster to process" than json, and that jsonb "supports indexing".
A rule of thumb for where a box goes: if any report, check or export reads it, give it a form_fields row. If it only travels with the form for display, jsonb is enough.
SQL column types for tax amounts, TINs and tax years
SQL column types for tax data should keep every value exact and unchanged. Store amounts as NUMERIC(14,2) or as integer cents, TINs as text so leading zeros survive, the tax year as a smallint, and dates as the date type. Each choice prevents a specific, quiet corruption of the numbers.
Amounts. The PostgreSQL 18 documentation on numeric types says numeric is "especially recommended for storing monetary amounts and other quantities where exactness is required." A NUMERIC(14,2) column holds up to twelve digits before the decimal point and two after it. The same page says that when a value has more fractional digits than the declared scale, the system rounds it, and when the digits to the left of the point exceed precision minus scale, it raises an error. That means a stray third decimal is rounded silently, so validate amounts before insert if a misread digit matters to you. Integer cents, such as 4825000 for $48,250.00, are the other exact choice; pick one and use it everywhere.
TINs. An employer identification number can start with a zero. Stored in an integer column, 01-2345678 becomes 12345678 and loses its format. Store it as text, with the hyphen, and let a CHECK constraint enforce the pattern. The PostgreSQL 18 documentation on character types says there is no performance difference among its character types and that "in most situations text or character varying should be used." For the person's own SSN, store only the last four digits that a masked source gives you, in a column named so nobody mistakes it for the full number.
Tax years. A smallint holds -32768 to +32767 in two bytes, according to the numeric types page, which covers any tax year. A CHECK constraint keeps it inside a sane range.
Dates. A 1098 origination date or a 1099-B sale date belongs in a date column. The PostgreSQL 18 documentation on date and time types marks the ISO 8601 form 1999-01-08 as the recommended input format, and shows that 1/8/1999 reads as January 8 or August 1 depending on the DateStyle setting. Normalize dates to YYYY-MM-DD before insert so the server setting never decides what a form said.
Child SQL tables for Box 12 codes, state lines and 1099-B lots
Child SQL tables hold any box that can repeat on one form: W-2 Box 12 code pairs, W-2 state and local lines, 1099 state lines and 1099-B lots. Each repeated item becomes one row with a foreign key to its form, so a form with one item and a form with forty use the same table.
W-2 Box 12 is the clearest case. The IRS General Instructions for Forms W-2 and W-3 (2026) say "On Copy A (Form W-2), do not enter more than four items in box 12" and tell employers to use a separate Form W-2 for the extra items. The same instructions say boxes 15 through 20 cover two states and two localities, and "If you need to report information for more than two states or localities, prepare a second Form W-2." A wide table with columns box12a_code through box12d_amount cannot express a person with six codes across two W-2s. A child table can, because each code is a row tied to whichever W-2 printed it.
The w2_box12_items table in the DDL keeps three things per row: the slot label (12a), the code and the amount. The primary key on (form_id, slot) stops one slot from being loaded twice. Example rows for a fictional W-2 look like this:
| form_id | slot | code | amount |
|---|---|---|---|
| 101 | 12a | D | 6500.00 |
| 101 | 12b | DD | 9420.00 |
| 101 | 12c | W | 1200.00 |
State lines follow the same pattern in a w2_state_lines table: form_id, line number, state, the employer's state ID, state wages and state tax on one row. The JSON side of the same idea, arrays of rows instead of numbered keys, is in the section on modeling repeated rows in a tax form data model.
A 1099-B lot table is the largest child table, since one consolidated brokerage statement can report hundreds of sales. Each lot row carries its own dates, proceeds and basis. The fields a lot needs are laid out in the 1099-B JSON format for lots, basis and wash sales, and each of those fields maps to one column of a lots table keyed by form_id.
How should SQL rows keep box numbers, review flags and passed checks?
SQL rows stay traceable when every value carries its box label, its field name, a review status and a record of the checks it passed. The box column lets a person find the value on the printed page, the status column drives a review queue, and a checks table shows why a value was accepted.
The box column is text, never an integer, because labels such as 12a and 14b are real values. Why the label travels next to a meaningful field name is covered in the section on keying a tax form JSON schema on box numbers or field names.
The status column on form_fields uses three values in the example: ok, blank and needs_review. A blank box is stored as a row with a NULL value and status blank, not as a zero. A zero means the issuer printed 0.00; NULL with blank means the box was empty. Keeping the difference lets a later check tell a missing value from a reported one.
The forms table adds a form-level review_status. A form moves from pending to approved once no field is needs_review. A query for the review queue is short:
-- Example: forms with at least one field waiting for a person
SELECT f.form_id, f.form_type, f.tax_year, count(*) AS fields_to_review
FROM forms f
JOIN form_fields ff ON ff.form_id = f.form_id
WHERE ff.status = 'needs_review'
GROUP BY f.form_id, f.form_type, f.tax_year;
Passed checks get their own table, because one form can pass several. An example form_checks table holds form_id, a check name such as ss_tax_is_6_2_pct_of_ss_wages, a passed boolean and a timestamp, with REFERENCES forms ON DELETE CASCADE. When a reviewer asks why a value was trusted, the answer is a row, not a memory.
Retention and deletion columns in a tax form SQL schema
Retention and deletion columns record when each piece of tax data should go. A delete_after date on documents says when the extracted rows expire, an original_deleted_at timestamp records when the uploaded file was removed, and cascading foreign keys make one delete remove every row that came from that file.
Two lifetimes usually differ. The original PDF or photo holds the full page, including anything a masked field left out, so many teams delete it soon after export. The extracted rows are smaller and are often kept longer for reconciliation. The example documents table handles this with original_storage_key, set to NULL when the file is deleted, and original_deleted_at, set at the same moment. The form, field and Box 12 rows stay.
When the rows themselves expire, one statement removes them:
-- Example: remove everything that came from expired uploads
DELETE FROM documents WHERE delete_after < current_date;
That works because each child table references its parent with ON DELETE CASCADE. The PostgreSQL 18 documentation on constraints says CASCADE "specifies that when a referenced row is deleted, row(s) referencing it should be automatically deleted as well." The same page notes that a delete on the referenced table needs a scan of the referencing table, and that declaring a foreign key "does not automatically create an index on the referencing columns." That is why the DDL adds forms_document_idx. Add the same kind of index on the form_id column of any child table whose primary key does not already start with it.
Matching a person across uploads without a full SSN is its own problem; the post on matching records with a masked SSN in API responses covers which keys to combine with the last four digits.
Tax form SQL schema mistakes: FLOAT money and box_1 column names
The two most common tax form SQL schema mistakes are storing money in FLOAT or REAL columns and naming columns after box positions, such as box_1. The first makes cents drift during sums. The second ties every query to a layout the IRS can change in any revision.
FLOAT or REAL for money. The PostgreSQL 18 numeric types page says floating-point types are inexact, that "some values cannot be converted exactly to the internal format and are stored as approximations," and adds: "If you require exact storage and calculations (such as for monetary amounts), use the numeric type instead." A total of thousands of 1099-INT amounts in a REAL column can end up a few cents off the sum of the printed forms. Why binary floats behave this way, and how to parse amounts before they reach the database, is covered in the post on decimal versus float for money in JSON.
Position-named columns. A column called box_1 means wages on a W-2 and something else on every other form, and it means nothing once a revision splits or relabels a box. Name the column or field after its meaning, wages, and keep the box label as data in the box column. The naming rules, with good and bad examples, are in the guide to designing a tax form JSON schema.
A few smaller mistakes are worth a check before you ship:
- One column for every kind of value. A single
value textcolumn forces every sum to cast, and a bad cast fails at report time instead of at insert. - No tax year on the form row. Without it, a 2025 and a 2026 W-2 from the same employer look like duplicates.
- Storing the full TIN when the source is masked. If the input only carries the last four digits, a column called
ssninvites someone to backfill it.
A worked example: total W-2 wages per tax year
Here are three fictional W-2s already loaded into the example tables. Two are for tax year 2026, from two employers, and one is for 2025. The wages field is Box 1, which the IRS W-2 instructions describe as "the total taxable wages, tips, and other compensation that you paid to your employee during the year."
-- Example data: fictional employers and amounts
INSERT INTO documents (source_filename, page_count, delete_after)
VALUES ('sample-w2s.pdf', 3, '2027-12-31'); -- document_id 1
INSERT INTO forms (document_id, form_type, tax_year, first_page, last_page,
issuer_name, issuer_tin, recipient_tin_last4)
VALUES (1, 'W-2', 2025, 1, 1, 'Example Bakery LLC', '01-2345678', '1234'),
(1, 'W-2', 2026, 2, 2, 'Example Bakery LLC', '01-2345678', '1234'),
(1, 'W-2', 2026, 3, 3, 'Sample Logistics Inc.', '98-7654321', '1234');
-- form_id 1, 2, 3
INSERT INTO form_fields (form_id, field_name, box, value_amount, status)
VALUES (1, 'wages', '1', 48250.00, 'ok'),
(2, 'wages', '1', 51300.00, 'ok'),
(3, 'wages', '1', 12480.55, 'ok');
SELECT f.tax_year,
count(*) AS w2_count,
sum(ff.value_amount) AS total_wages
FROM forms f
JOIN form_fields ff ON ff.form_id = f.form_id
WHERE f.form_type = 'W-2'
AND ff.field_name = 'wages'
GROUP BY f.tax_year
ORDER BY f.tax_year;
The query returns two rows from the example data:
| tax_year | w2_count | total_wages |
|---|---|---|
| 2025 | 1 | 48250.00 |
| 2026 | 2 | 63780.55 |
The 2026 total is 51,300.00 plus 12,480.55, exact to the cent because both columns are NUMERIC. Because the query filters on a field name rather than a column, the same shape sums federal_income_tax_withheld across W-2s and 1099s by changing one filter.
Rows like these load cleanly when the source output is already typed. Schema Tax exports each form with fixed field names and box numbers as JSON, CSV or Excel, and its API returns the same JSON, billed per page, with access by request ("Ask about API access"). Each field then maps straight to a form_fields row. You can see which forms it reads, or Get started with the free plan. For a mortgage statement, the 1098 extraction API guide shows how two lenders' statements land in these same tables.