插入完整的行
insert into customers
values(
null,
'LaPew',
'Los Angeles'
);
对每个列都提供一个值,如果没有值,使用null(假设该列允许指定空值)。如第一列cust_id,该列由MySQL为自动增量。
以上方法,高度依赖表中列定义的顺序——改进:明确给出列名,value中的值与其一一对应。
insert into customers(
cust_id,
cust_name,
cust_city)
values(
null,
'LaPew',
'Los Angeles'
);
插入多行
例:每组值之间用逗号分隔。
insert into customers(
cust_name,
cust_city)
values(
'LaPew',
'Los Angeles'
),
values(
'Martin',
'New York'
);
插入检索出的数据
把selete语句的结果插入表中,即insert-selete
例:从表custnew中,把所有数据导入新表customers中
insert into customers(
cust_id,
cust_name,
cust_city)
selete
cust_id,
cust_name,
cust_city
from custnew;
不一定列名匹配:位置匹配