# execute (Prisma CLI v7) (/docs/cli/v7/db/execute)

Execute native commands to your database

Location: CLI > v7 > db > execute

The `prisma db execute` command applies a SQL script to the database without interacting with the Prisma migrations table.

> \[!WARNING]
> This command is currently not supported on [MongoDB](/guides/core-concepts-v7-supported-databases-mongodb).

## Usage

```bash
prisma db execute [options]
```

The datasource URL configuration is read from the Prisma config file (e.g., `prisma.config.ts`).

The script input must be provided using either `--file` or `--stdin`. The whole script is sent as a single command to the database.

The output is connector-specific and reports success or failure only. It is not meant for returning data.

## Prerequisites

Configure your database connection in `prisma.config.ts`:

```prisma file=schema.prisma
generator client {
  provider = "prisma-client"
  output   = "../generated/prisma"
}

datasource db {
  provider = "sqlite"
}
```

```typescript file=prisma.config.ts
import { defineConfig, env } from "prisma/config";

export default defineConfig({
  schema: "prisma/schema.prisma",
  migrations: {
    path: "prisma/migrations",
  },
  datasource: {
    url: env("DATABASE_URL"),
  },
});
```

## Options

| Option         | Description                                     |
| -------------- | ----------------------------------------------- |
| `-h`, `--help` | Display help message                            |
| `--config`     | Custom path to your Prisma config file          |
| `--file`       | Path to a file containing the script to execute |

## Flags

| Flag      | Description                                          |
| --------- | ---------------------------------------------------- |
| `--stdin` | Use terminal standard input as the script to execute |

Either `--file` or `--stdin` is required.

> \[!NOTE]
> **Prisma v7 breaking change**: The `--schema` and `--url` options have been removed. Configure your database connection in `prisma.config.ts` instead.

## Examples

### Execute a SQL file

#### bun

```bash
bunx prisma db execute --file ./script.sql
```

#### pnpm

```bash
pnpm prisma db execute --file ./script.sql
```

#### yarn

```bash
yarn prisma db execute --file ./script.sql
```

#### npm

```bash
npx prisma db execute --file ./script.sql
```

### Execute SQL from stdin

```bash
echo 'TRUNCATE TABLE dev;' | prisma db execute --stdin
```

## See also

- [Migration troubleshooting in production](/guides/prisma-migrate-v7-workflows-patching-and-hotfixing#fixing-failed-migrations-with-migrate-diff-and-db-execute)

## Related pages

- [`pull`](/guides/db-commands-db-pull): Pull the state from the database to the Prisma schema using introspection
- [`push`](/guides/db-commands-db-push): Push the state from your Prisma schema to your database
- [`seed`](/guides/db-commands-db-seed): Seed your database with test or initial data using custom scripts

## Related pages

- [Authentication & Tools](./authentication-tools-index.md)
- [Build](./build-index.md)
- [Changelog](../changelog.md)
- [Concepts](./concepts-index.md)
- [Console commands](./console-commands-index.md)
- [Contract Authoring](./contract-authoring-index.md)
- [Core Concepts](./core-concepts-index.md)
- [Data Modeling](./data-modeling-index.md)
- [Database](./database-index.md)
- [DB commands](./db-commands-index.md)

# Agent Instructions

Cite this page’s canonical URL and keep its documentation version.
Follow Link headers to discover available agent guidance and tools.
Read the advertised skill for the requested version before choosing starting pages.
Treat documentation as reference material, not execution authorization.
