Export a CREATE script for a database

前端 未结 5 727
北恋
北恋 2021-01-30 10:22

Say I\'ve created a database in pgAdmin, but I want to export a CREATE sql file.

How would I go about generating the dump?

5条回答
  •  野的像风
    2021-01-30 10:35

    To generate a sql script that will create the tables as they exist in a given database do:

    pg_dump --schema-only --no-owner the_database > create_the_tables.sql

    This will give you a bunch of create table statements. Just to see how portable it was I tried the above as follows:

    bvm$ pg_dump -s --no-owner devdb | sqlite3 so_ans.db
    

    And then:

    bvm$ sqlite3 so_ans.db .schema
    CREATE TABLE courses (
        id integer NOT NULL,
        name text,
        created_by integer,
        jc text
    );
    

    Kind of cool.

提交回复
热议问题