---
title: "SQL tables written by more than one file | Metacenta"
description: "For SQL projects without dbt: which tables two files write, why the last one to run wins, and when two writers are loading different partitions on purpose."
url: "https://metacenta.com/rules/sql-relation-written-twice"
updated: "2026-10-14"
tokens: 519
---

Lineage integrity · rule sql-relation-written-twice

# SQL tables written by more than one file

A Metacenta review checks this under the rule **Each relation has one writer**. Everything below applies whether or not you ever commission one.

## What this rule checks

For SQL projects without dbt, this rule flags each table or view that two or more files write. A write is a `create table`, `create view`, `insert`, `merge`, `update` or `delete`. A `query.sql` with no explicit write, inside a `<dataset>/<table>/` folder, counts as writing that table. Assertion files are not writers.

## Why it matters

Whichever file runs last wins. The table's contents then depend on scheduling order rather than on either file.

## How to fix it

**Give each relation one writer.** Keep one writer per table. If the files load different partitions on purpose, merge them into one parameterised file, or say so in each.

## When it is fine to leave

Files that load different partitions or date ranges on purpose, such as a daily load beside a one-off backfill, are not competing. A cleanup script that deletes old rows also counts as a writer here. Say which applies in each file.

## What we need to check it

The `.sql` files, read from your repository with read-only access or uploaded. We match relations by their last two name parts, such as `dataset.table`, so the finding is medium confidence.

[Ask about a review](https://metacenta.com/enquire?src=rule-sql-relation-written-twice&via=md)

## Related pages

- [dbt dependency cycles in the model DAG](https://metacenta.com/rules/dependency-cycle)
- [dbt models with a hardcoded table name](https://metacenta.com/rules/hardcoded-table-reference)
- [dbt exposures: what they are and how to declare them](https://metacenta.com/rules/model-possibly-unused)
- [Deep dbt lineage: long chains of models](https://metacenta.com/rules/deep-lineage)
- [A sample review, as a client reads it](https://metacenta.com/sample)
- [All published rules](https://metacenta.com/rules)
- [How a review is assessed](https://metacenta.com/standard)
