I am using MySQL Workbench CE for Windows version 5.2.40.
I want to execute the following SQL queries together. However I can only execute the SQL queries by first executing the CREATE TABLE
query, and then executing the INSERT INTO
query and after that executing the SELECT
query.
CREATE TABLE testTable(
Name VARCHAR(20),
Address VARCHAR(50),
Gender VARCHAR(10)
)
INSERT INTO testTable
VALUES
('Derp', 'ForeverAlone Street', 'Male'),
('Derpina', 'Whiterun Breezehome', 'Female')
Select * FROM testTable
So how do I execute the CREATE TABLE
, INSERT INTO
and the SELECT
queries by one click?
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.
MySQL also supports the execution of a string containing multiple statements separated by semicolon ( ; ) characters. This capability is enabled by special options that are specified either when you connect to the server with mysql_real_connect() or after connecting by calling mysql_set_server_option() .
To do that, first select the desired database from the left column menu by double-clicking it. Then type in the MySQL query you want to run in the text field in the middle of the program window and use the yellow lightning button above that text field to run the query.
To run SQL script in MySQL, use the MySQL workbench. First, you need to open MySQL workbench. Now, File -> Open SQL Script to open the SQL script. Note − Press OK button twice to connect with MySQL.
You could use Ctrl+Shift+Enter to run everything with semicolon end.
For Mac ⌘+shift+return
Add a semicolon after each statement:
CREATE TABLE testTable( Name VARCHAR(20), Address VARCHAR(50), Gender VARCHAR(10) ); INSERT INTO testTable VALUES ('Derp', 'ForeverAlone Street', 'Male'), ('Derpina', 'Whiterun Breezehome', 'Female'); SELECT * FROM testTable;
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