Tracing toolGolang HTTP routerGolang ClickHouseBlog
Golang ORMGolang ORM
Getting started
PostgreSQL
Newsletter open in new window
Reference open in new window
GitHub open in new window
Getting started
PostgreSQL
Newsletter open in new window
Reference open in new window
GitHub open in new window
  • Guide

    • Introduction
    • Getting started
    • Drivers and dialects
    • Defining models
  • Querying

    • Writing queries
    • SQL placeholders
    • SELECT
    • WHERE
    • Common table expressions
    • INSERT
    • UPDATE
    • DELETE
    • CREATE TABLE
    • DROP TABLE
      • API
      • Example
    • TRUNCATE TABLE
    • ORM relations
  • Essentials

    • Starter kit
    • Migrations
    • Fixtures
    • Debugging
  • Tutorials

    • Running Bun in production
    • Monitoring performance and errors
    • Transactions
    • Soft deletes
    • Hooks
    • Custom types
    • Cursor pagination
    • Writing complex queries
    • Migrating from go-pg

# Drop Table [PostgreSQL MySQL]

  • API
  • Example

# API

For the full list of supported methods, see DropTableQueryopen in new window.

db.NewDropTable().

	Model(&strct).

	Table("table1"). // quotes table names
	TableExpr("table1"). // arbitrary unsafe expression
	ModelTableExpr("table1"). // overrides model table name

	IfExists().

	Cascade().
	Restrict().

	Exec(ctx)

# Example

To drop PostgreSQL/MySQL table:

_, err := db.NewDropTable().Model((*Book)(nil)).IfExists().Exec(ctx)
if err != nil {
	panic(err)
}
Last Updated:

CREATE TABLE TRUNCATE TABLE