您的位置
主页 > 网站技术 > 数据库 > » 正文

Mysql 原生语句中save or update 的写法汇总(2)

来源: 锦尚中国 点击:


If you use the IGNORE keyword, errors that occur while executing the INSERT statement are ignored. For example, without IGNORE, a row that duplicates an existing UNIQUE index or PRIMARY KEY value in the table causes a duplicate-key error and the statement is aborted. With IGNORE, the row is discarded and no error occurs. Ignored errors may generate warnings instead, although duplicate-key errors do not.

Mysql官方文档中提供标准的语法:

复制代码 代码如下:


INSERT  IGNORE
    INTO tbl_name
    [PARTITION (partition_name,...)]
    [(col_name,...)]
    {VALUES | VALUE} ({expr | DEFAULT},...),(...),...

或者

复制代码 代码如下:


INSERT IGNORE
    [INTO] tbl_name
    [PARTITION (partition_name,...)]
    [(col_name,...)]
    SELECT ...

可见除了多了个IGNORE关键字以外,跟一般INSERT语句并无区别。

举个栗子:

1.建一张测试用的表

复制代码 代码如下:




首页  - 关于站长圈  - 广告服务  - 联系我们  - 关于站长圈  - 网站地图  - 版权声明