Skip to main content
Prisma Documentation Docs
current

Search documentation

Type to search this documentation.

On this pageOverview

execute (Prisma CLI v7)

Execute native commands to your database

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

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.

Configure your database connection in prisma.config.ts:

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

datasource db {
  provider = "sqlite"
}
TypeScript
import { defineConfig, env } from "prisma/config";

export default defineConfig({
  schema: "prisma/schema.prisma",
  migrations: {
    path: "prisma/migrations",
  },
  datasource: {
    url: env("DATABASE_URL"),
  },
});
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
Flag Description
--stdin Use terminal standard input as the script to execute

Either --file or --stdin is required.

bun
bunx prisma db execute --file ./script.sql
pnpm
pnpm prisma db execute --file ./script.sql
yarn
yarn prisma db execute --file ./script.sql
npm
npx prisma db execute --file ./script.sql
Bash
echo 'TRUNCATE TABLE dev;' | prisma db execute --stdin
Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu