---
title: "Duplicate SQL files in a warehouse repo | Metacenta"
description: "For SQL projects without dbt: which transformation files hold identical SQL, why copies drift apart, and when a per-dataset copy is deliberate."
url: "https://metacenta.com/rules/sql-duplicate-logic"
updated: "2026-10-14"
tokens: 597
---

Maintainability · rule sql-duplicate-logic

# Duplicate SQL files in a warehouse repo

A Metacenta review checks this under the rule **No SQL file duplicates another**. Everything below applies whether or not you ever commission one.

## What this rule checks

For SQL projects without dbt, this rule flags files that write a relation and contain the same SQL as another such file. We compare a fingerprint of each whole file, ignoring comments, case and whitespace. Any table name the file writes to is part of it.

## Why it matters

A fix applied to one copy is missed in the others, and the tables drift apart. Nobody can tell from the tables alone which copy holds the current logic.

## How to fix it

**Remove duplicated SQL files.** Keep one definition and have the others read from it, or generate them from one template.

Before:

```sql
-- shop_eu/orders_daily/query.sql
select ordered_at, count(*) as orders
from raw.shop_orders group by 1

-- shop_uk/orders_daily/query.sql
select ordered_at, count(*) as orders
from raw.shop_orders group by 1
```

After:

```sql
-- shop_eu/orders_daily/query.sql
select ordered_at, count(*) as orders
from raw.shop_orders group by 1

-- shop_uk/orders_daily/view.sql
create view shop_uk.orders_daily as
select ordered_at, orders
from shop_eu.orders_daily
```

## When it is fine to leave

A copy per dataset that a script regenerates from one template is maintained in one place already. So is a copy kept only until a consumer moves. Tell us which applies, and the finding comes out of your report.

## What we need to check it

The `.sql` files, read from your repository with read-only access or uploaded. The fingerprint is a hash, and we keep none of the SQL. Identical text is a high-confidence match.

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

## Related pages

- [Duplicate logic across dbt models](https://metacenta.com/rules/duplicate-model-logic)
- [select * in dbt models](https://metacenta.com/rules/select-star)
- [dbt models with too many CTEs](https://metacenta.com/rules/high-cte-count)
- [dbt layer naming: inconsistent model prefixes](https://metacenta.com/rules/layer-naming-mismatch)
- [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)
