【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、创建表并把数据导入到新表


CREATE TABLE CustCopy AS

SELECT *

FROM Customers


©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容