MySQL工作台只读取最后一行

时间:2016-03-05 15:43:02

标签: mysql

我正在学习使用MySql工作台,每次我使用脚本时它只读取最新的语句,例如在这样的代码中

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', 'sales@villagetoys.com');
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', 'jjones@fun4all.com');
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', 'dstephens@fun4all.com');
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');

我只有最后一次创作

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');

其他人不起作用,我必须逐行排列

2 个答案:

答案 0 :(得分:2)

我正在使用快捷键 Crtl + Enter 来执行代码,这只适用于最后一行,以正确执行它所写的所有代码正确的快捷方式< KBD>键Crtl + + 输入

答案 1 :(得分:0)

虽然您已经给出了正确答案,但我只是建议您也可以在一个语句中进行多次插入,这也可以提高性能。

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', 'jjones@fun4all.com'
), (
     '1000000004', 'Fun4All', '829 Riverside Drive', 'Phoenix', 'AZ', '88888', 'USA', 
     'Denise L. Stephens', 'dstephens@fun4all.com'
);

请注意,如果您的插入查询大于max_allowed_packet --> SHOW VARIABLES LIKE 'max_allowed_packet';,则可能会达到max_query_size限制