插入数据

1.向原表中某些字段中插入一条记录

语法:insert into +表名(表中的字段,,)value(字段所对应的记录,,);

mysql> insert into joke (gid,name) value(0,"joker");
Query OK, 1 row affected (0.09 sec)

2.向原表的字段中插入多条记录

语法:insert into +表名(表中的字段,,)values(字段所对应的记录,,)(字段所对应的记录);

mysql> insert into joke (gid,name) values(0,"joker"),(1,"jhj");
Query OK, 2 rows affected (0.14 sec)
Records: 2  Duplicates: 0  Warnings: 0

3.向原表的字段中插入多条记录

语法:insert into+表名 select v1,v2 union all select v1,v2;

mysql> insert into book select "abc","bdd" union  all
    -> select "add","dsf";
Query OK, 2 rows affected (0.16 sec)
Records: 2  Duplicates: 0  Warnings: 0

4.复制旧表的信息到新表(假设两个表的表结构一样)

语法:insert into+新表+select语句;

mysql> insert into q1 select * from 4inall where sage=18;
Query OK, 7 rows affected (0.28 sec)
Records: 7  Duplicates: 0  Warnings: 0

5.复制旧表信息到新表(假设两个的表的表结构不一样)。

语法::insert into+新表+字段名+select语句;

mysql> insert into q1 (sname)select 4inall.s from 4inall where t=2;
Query OK, 5 rows affected (0.13 sec)
Records: 5  Duplicates: 0  Warnings: 0

6.向原本中插入数据(不能是其他表的数据)

语法:insert into 原表名 set 原表字段名=原表字段名(=“具体指”可有可无);

mysql> insert  into  4a set sname=sname="赵六";
Query OK, 1 row affected (0.29 sec)

mysql> insert  into  4a set sname=sname+1;
Query OK, 1 row affected (0.21 sec)

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值