I have a create table query, an update query ,and then drop table query. I need to run these three queries in one shot. What is the best way to do this?
Example
1st Query: Create table A.
2nd Query: Update value in table A
3rd Query: Drop table A.
Instead of running these three queries one by one, I want to run them in on go either by PLSQL or some other way. Please help.
You can include multiple SQL statements on the SQL query panel. The exceptions are CALL and CREATE PROCEDURE statements. These statements must be used alone in a query.
How to run Multiple SQL Queries in MySQL Workbench explains how you can run multiple statements in single query window by separating them with semicolon ; You can have different types of statements such as delete, update or insert in single query window and all can be executed with single click.
Simply put three queries one after the other in a . sql file, with semi-colons after each statement, then execute it as a script (either on a SQL*Plus prompt using @scriptname. sql or in TOAD/SQL Developer [or equivalent] using its script execution function).
In SqlDeveloper preferences: Tools > Preferences > Database > Worksheet check the option for New Worksheet to use unshared connction . This will allow you to execute multiple queries at the same time, each in each tab.
Put the 3 queries following each other separated by a semi-colon:
SELECT *
FROM table_to_be_selected;
DROP TABLE the table_to_be_dropped;
TRUNCATE TABLE table_to_be_truncated;
You can concatenate these queries in a string and execute that string.
Another way is this solution.
Simply put three queries one after the other in a .sql file, with semi-colons after each statement, then execute it as a script (either on a SQL*Plus prompt using @scriptname.sql
or in TOAD/SQL Developer [or equivalent] using its script execution function).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With