十一.数据插入
- 数据插入
插入完整行
insert into customers
values('1000000006',
'toy land',
'123 Any street',
'new york',
'NY',
'USA',
NULL
NULL);
但是这样必须让插入的数据保持和表中每行数据完全一样的顺序,很不安全
更安全的做法是限定每个数据表示的列
insert into customers(cust_id,
cust_name,
cust_address,
cust_city,
cust_state,
cust_zip,
cust_country,
cust_contact,
cust_email)
values('1000000006',
'toy land',
'123 Any street',
'new york',
'NY',
'USA',
NULL
NULL);
只插入部分行而把其他的留着也是可以的
也可以把一个表中检索出的数据插入另一个表中:
insert into customers(cust_id,
cust_name,
cust_address,
cust_city,
cust_state,
cust_zip,
cust_country)
select cust_id,
cust_name,
cust_address,
cust_city,
cust_state,
cust_zip,
cust_country
from Custnew;
#但是进行这种操作的时候要注意,主键值(cust_id不可以重复,
否则插入会失败)
将一个表复制到另一个表
select*
into custcopy
from customers;
或
creat table custcopy as
slect * from customers;
#适用于mySQL,Oracle,PostgreSQL,SQLite等