Reputation: 231
I am learning to use MySql workbench, everytime i use scripts it only reads the latest statement, for example in a code like this
INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact, cust_email)
VALUES('1000000001', 'Village Toys', '200 Maple Lane', 'Detroit', 'MI', '44444', 'USA', 'John Smith', '[email protected]');
INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact)
VALUES('1000000002', 'Kids Place', '333 South Lake Drive', 'Columbus', 'OH', '43333', 'USA', 'Michelle Green');
INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact, cust_email)
VALUES('1000000003', 'Fun4All', '1 Sunny Place', 'Muncie', 'IN', '42222', 'USA', 'Jim Jones', '[email protected]');
INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact, cust_email)
VALUES('1000000004', 'Fun4All', '829 Riverside Drive', 'Phoenix', 'AZ', '88888', 'USA', 'Denise L. Stephens', '[email protected]');
INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact)
VALUES('1000000005', 'The Toy Store', '4545 53rd Street', 'Chicago', 'IL', '54545', 'USA', 'Kim Howard');
I only have the last creation
INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact)
VALUES('1000000005', 'The Toy Store', '4545 53rd Street', 'Chicago', 'IL', '54545', 'USA', 'Kim Howard');
The others do not work and i have to put them in line by line
Upvotes: 0
Views: 302
Reputation: 31743
While you already gave the correct answer, I just wanted to suggest that you can also make multiple inserts in one statement which also improves performance.
INSERT INTO Customers(
cust_id, cust_name, cust_address, cust_city,
cust_state, cust_zip, cust_country, cust_contact, cust_email
) VALUES (
'1000000003', 'Fun4All', '1 Sunny Place', 'Muncie', 'IN', '42222', 'USA',
'Jim Jones', '[email protected]'
), (
'1000000004', 'Fun4All', '829 Riverside Drive', 'Phoenix', 'AZ', '88888', 'USA',
'Denise L. Stephens', '[email protected]'
);
Please be aware that you might hit the max_query_size limit if your insert query is greater than max_allowed_packet --> SHOW VARIABLES LIKE 'max_allowed_packet';
Upvotes: 0
Reputation: 231
I was using the shortcut Crtl+Enter to execute code, that only works for the last line, to properly execute all the code it's written the correct shortcut is Crtl+Shift+Enter.
Upvotes: 3