SQL必知必会学习笔记11-Kane

十一.数据插入

  • 数据插入
    插入完整行
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等
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值