[MYSQL -19]插入数据

1、数据插入

INSERT 用来插入行到数据库表。插入有多种形式:

  • 插入完整的行
  • 插入行的一部分
  • 插入多行
  • 插入某些查询的值
#缺点是不安全,必须按照表中定义列的顺序插入数据,如果表的结构发生改变,将会和预计的结果不一致甚至失败。
#有效的方法是插入列名。
insert into customers
values(
    NULL,
    'Pep E. LaPew',
    '100 Main Street',
    'Los Angeles',
    'CA',
    '90046',
    'USA',
    NULL,
    NULL
    );

插入列名:

insert into customers(
    CUST_NAME,
    cust_address,
    cust_city,
    cust_state,
    cust_zip,
    cust_country,
    cust_contact,
    cust_email)
values(
    'Pep E. LaPewG',
    '100 Main Street',
    'Los Angeles',
    'CA',
    '90046',
    'USA',
    NULL,
    NULL);

INSERT LOW_PRIORITY INTO#降低插入的优先级,提高性能

2、插入多行数据

insert into customers(
    CUST_NAME,
    cust_address,
    cust_city,
    cust_state,
    cust_zip,
    cust_country,
    cust_contact,
    cust_email)
values(
    'Pep E. LaPewG',
    '100 Main Street',
    'Los Angeles',
    'CA',
    '90046',
    'CHN',
    NULL,
    NULL),
    (
    'M.Martian',
    '42 Galaxy Way',
    'New Yotk',
    'NY',
    '11213',
    'USA',
    NULL,
    NULL);

3、插入检索出的数据

insert into customers(
    CUST_NAME,
    cust_address,
    cust_city,
    cust_state,
    cust_zip,
    cust_country,
    cust_contact,
    cust_email)
SELECT  CUST_NAME,
    cust_address,
    cust_city,
    cust_state,
    cust_zip,
    cust_country,
    cust_contact,
    cust_email
from custnew;#先建立的一个表
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值