user10531062
user10531062

Reputation: 197

How to run multiple sql statements in Postgres using the tool PGADMIN?

I have 170 Alter Drop Constraint statement, 120 Truncate table, 120 Insert table and 170 Alter Add Constraint. All of these should be run in one in one script as batch script and I'm using PGADMIN IV tool.

Tried executing them between Begin and End as follows like Oracle,

BEGIN 
  ALTER Statement1..,,  ;
  ALTER Statement2..,,  ;
  TRUNCATE Statement3..,,  ;
  TRUNCATE Statement4..,,  ;
  INSERT Statement5..,,    ;
  INSERT Statement6..,,    ;
  COMMIT;
  ALTER Statement7..,,     ;
  ALTER Statement8..,,     ;
  ---
  -----
  -------
  ---------
  COMMIT;
END;

But its not working,

Can some one please give a suggestion on how I can do this?

Upvotes: 8

Views: 29778

Answers (1)

Dhwani Katagade
Dhwani Katagade

Reputation: 1290

It is not very clear from your question what you actually intend to do. Is it that you want to run all your statements in one script or one transaction?

If you need to run them in one script, then just running them as follows in PGADMIN should work.

  ALTER Statement1 ;
  ALTER Statement2 ;
  TRUNCATE Statement3 ;
  TRUNCATE Statement4 ;
  INSERT Statement5 ;
  INSERT Statement6 ;
  ALTER Statement7 ;
  ALTER Statement8 ;

And so on.

On the other hand if you want to run them all in a transaction, then just enclose the statements in a BEGIN and COMMIT as follows.

  BEGIN ;
  ALTER Statement1 ;
  ALTER Statement2 ;
  TRUNCATE Statement3 ;
  TRUNCATE Statement4 ;
  INSERT Statement5 ;
  INSERT Statement6 ;
  ALTER Statement7 ;
  ALTER Statement8 ;
  COMMIT ;

I don't see any difference between how you would run this in PGADMIN versus how you would run this using a client like psql.

Upvotes: 10

Related Questions