2016-03-05 24 views
0

我學習使用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', '[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'); 

我只有最後創建

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

其他人不工作,我必須把它們放在一行行

+1

試試這個吧。你可能會擊中max_query_size極限[使用'按Ctrl + A'選擇所有,然後再執行。] – 1000111

+0

做ü嘗試在插入命令之間使用union命令 –

+0

順便說一下,'UNION'是用於'SELECT語句'的 – 1000111

回答

1

我是使用快捷鍵Crtl +輸入執行代碼,只適用於最後一行,正確地執行它的所有書面正確的快捷方式的代碼是鍵Crtl ++輸入

+0

請記住'Crtl + Shift + Enter'只執行選擇如果有的話。 –

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', '[email protected]' 
), (
    '1000000004', 'Fun4All', '829 Riverside Drive', 'Phoenix', 'AZ', '88888', 'USA', 
    'Denise L. Stephens', '[email protected]' 
); 

請注意,如果您插入查詢大於max_allowed_packet --> SHOW VARIABLES LIKE 'max_allowed_packet';