【SQL】(十五):插入數據

本系列為自己學習時的筆記及心得體會,轉載請注明出處。

1、插入完整的行


INSERT INTO Customers

VALUES

( '1000000006', 'Lottie Toys', '200 Maple Lane', 'Detroit', 'MI', '44444', 'USA', 'John Smith', 'sales@lottietoy.com' );


上述語句不安全,更安全的語句如下:


INSERT INTO Customers ( cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact, cust_email )

VALUES

( '1000000006', 'Lottie Toys', '200 Maple Lane', 'Detroit', 'MI', '44444', 'USA', 'John Smith', 'sales@lottietoy.com' );


2、插入部分行


INSERT INTO Customers ( cust_id, cust_name, cust_address, cust_zip, cust_country, cust_contact, cust_email )

VALUES

( '1000000006', 'Lottie Toys', '200 Maple Lane', 'USA', 'John Smith', 'sales@lottietoy.com' );


3、插入檢索出的數據

如下截圖的SQL,把CustNew表的數據復制到Customers表(注意:Custnew表的cust_id應與Customers表的cust_id不同)

上述CustNew和Customers表的列名可不一樣,因為它是按照列的位置去插入的。

4、創(chuàng)建表并把數據導入到新表


CREATE TABLE CustCopy AS

SELECT *

FROM Customers


?著作權歸作者所有,轉載或內容合作請聯系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內容