MySQL学习笔记:插入数据

本文为本人学习书籍《MySQL必知必会》笔记系列,欢迎持续关注,有问题随时留言评论,一起探讨学习~

19 插入数据

数据插入INSERT分为:

  1. 插入完整的行;
  2. 插入行的一部分;
  3. 插入多行;
  4. 插入某些查询结果

19.1插入完整的行

INSERT INTO customers(cust_name,
                      cust_address,
											cust_city,
											cust_state,
											cust_zip,
											cust_country,
											cust_contact,
											cust_email) 
VALUES('刘洋',
       '北京市朝阳区中国传媒大学',
			 '北京',
			 '北京',
			 '10010',
			 '中国',
			 '杨子',
			 '15699834658@126.com');

19.2插入行的一部分:即只有部分列有值

INSERT INTO customers(cust_name,
											cust_city,
											cust_state,
											cust_country,
											cust_contact,
											cust_email) 
VALUES('李若寒',
			 '武汉',
			 '湖北',
			 '中国',
			 '涵涵',
			 '18966439875@126.com');

19.3 插入多个行

INSERT INTO customers(cust_name,
											cust_country,
											cust_contact,
											cust_email) 
VALUES('赵梓明',
			 '中国',
			 'MM',
			 '1891968875@126.com'),
			 ('刘露露',
			 '中国',
			 'LL',
			 '1796568875@126.com');

19.4 插入检索结果INSERT SELECT

使用INSERT SELECT从custnew中将所有数据导入customers表

INSERT INTO customers(cust_id,
                      cust_name,
                      cust_address,
											cust_city,
											cust_state,
											cust_zip,
											cust_country,
											cust_contact,
											cust_email) 
SELECT id,
       cust_name,
       cust_address,
			 cust_city,
			 cust_state,
			 cust_zip,
			 cust_country,
			 cust_contact,
			 cust_email
FROM custnew;
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值