本文为本人学习书籍《MySQL必知必会》笔记系列,欢迎持续关注,有问题随时留言评论,一起探讨学习~
19 插入数据
数据插入INSERT分为:
- 插入完整的行;
- 插入行的一部分;
- 插入多行;
- 插入某些查询结果
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;