61 Star 426 Fork 144

xuthus / 数据库SQL实战

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
35.批量插入数据不使用replace操作.md 794 Bytes
一键复制 编辑 原始数据 按行查看 历史
xuthus 提交于 2019-08-12 23:23 . add:all

批量插入数据,不使用replace操作

题目描述

对于表actor批量插入如下数据,如果数据已经存在,请忽略,不使用replace操作

CREATE TABLE IF NOT EXISTS actor (
actor_id smallint(5) NOT NULL PRIMARY KEY,
first_name varchar(45) NOT NULL,
last_name varchar(45) NOT NULL,
last_update timestamp NOT NULL DEFAULT (datetime('now','localtime')))
actor_id first_name last_name last_update
'3' 'ED' 'CHASE' '2006-02-15 12:34:33'

答案

insert or ignore into actor values (3,'ED','CHASE','2006-02-15 12:34:33');

题解

MySQL语法:

insert ignore into actor values (3,'ED','CHASE','2006-02-15 12:34:33');
SQL
1
https://gitee.com/xuthus5/Database-SQL-Actual-Combat.git
git@gitee.com:xuthus5/Database-SQL-Actual-Combat.git
xuthus5
Database-SQL-Actual-Combat
数据库SQL实战
master

搜索帮助