How to generate the statement CREATE TABLE for an existing table in postgreSQL

0 votes
I have created a table in postgreSQL.

How to get the create table statement for a table that is already existing in Postgres via commandline or SQL statement?
Feb 9, 2022 in Database by Vaani
• 7,020 points
5,932 views

1 answer to this question.

0 votes

Generate table creation statement for an existing table
Use command line tool:

pg_dump -t 'schema_name.table_name' --schema-only database_name
 

Use TablePlus GUI Tool:

Select the table that you want to replicate from the list in the left sidebar.
Switch to the Structure tab at the bottom, or use shortcut keys Cmd + Ctrl + ]
Click on the Definition button on the top bar.
You will notice the table creation statement to copy.

pg_dump

pg_dump — extract a PostgreSQL database into a script file or other archive file

pg_dump [connection-option...] [option...] [dbname]

answered Feb 9, 2022 by Neha
• 9,060 points

Related Questions In Database

0 votes
2 answers
0 votes
2 answers

How to select the nth row in a SQL database table?

SELECT * FROM ( SELECT ID, NAME, ROW_NUMBER() ...READ MORE

answered Apr 23, 2020 in Database by anand
• 140 points
25,038 views
0 votes
1 answer

How to create an excel file in android?

In Android, create Excel XLSX or XLS ...READ MORE

answered Apr 4, 2022 in Database by Edureka
• 13,670 points
1,024 views
0 votes
0 answers
0 votes
2 answers

Install postgreSQL on Ubuntu

Follow the below commands to install PostgreSQL (PSQL) ...READ MORE

answered Nov 12, 2020 in Database by Prachi
• 140 points
934 views
0 votes
1 answer

Access progrs prompt without switching accounts

Use the following to get the postgres prompt ...READ MORE

answered Mar 22, 2019 in Database by Mahi
654 views
0 votes
1 answer

Create new role - postgresql on ubuntu

If you are logged in as the postgres account, ...READ MORE

answered Mar 22, 2019 in Database by Danny
558 views
0 votes
1 answer

How would I find the second largest salary from a employee table? [closed]

To find the 2nd largest salary from ...READ MORE

answered Feb 8, 2022 in Database by Vaani
• 7,020 points
554 views
0 votes
1 answer

How to rename a column in a database table using SQL?

For SQL Server, use sp_rename USE AdventureWorks; GO EXEC sp_rename 'Customers.CustomerTerritory.TerritoryID', ...READ MORE

answered Feb 9, 2022 in Database by Neha
• 9,060 points
520 views
0 votes
1 answer

How to do version control for SQL Server database?

Not only can you compare objects at ...READ MORE

answered Feb 15, 2022 in Database by Neha
• 9,060 points
435 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP