niuke题霸SQ/L篇

SQL33 创建一个actor表,包含如下列信息

CREATE TABLE actor
(
    actor_id    smallint(5) not null comment'主键id', 
    first_name  varchar(45) not null comment'名字',
    last_name   varchar(45) not null comment'姓氏',
    last_update    date     not null comment'日期',
    primary key(actor_id)
)

注:comment添加备注

SQL 34 批量插入数据

--虽然简单但是不安全,高度依赖表中列的定义顺序,尽量避免使用
INSERT INTO actor 
VALUES(1,'PENELOPE','GUINESS','2006-02-15 12:34:33'),
      (2,'NICK','WAHLBERG','2006-02-15 12:34:33')


--更繁琐,但更安全,表结构变化时也不会出错
insert into actor
(actor_id,first_name,last_name,last_update)
values(1,"PENELOPE","GUINESS","2006-02-15 12:34:33"),
      (2,"NICK","WAHLBERG","2006-02-15 12:34:33")

题解1积累:批量插入数据(比如上百万)到MySQL中的多种操作_牛客博客

注:可省略列的条件(允许NULL值或已给出默认值)

SQL35 对于表actor插入如下数据,如果数据已经存在,请忽略(不支持使用replace操作)

题解:【Mysql】对于表actor插入如下数据,如果数据已经存在,请忽略(不支持使用replace操作)_牛客博客

-- mysql中常用的三种插入数据的语句:
-- insert into表示插入数据,数据库会检查主键,如果出现重复会报错;
-- replace into表示插入替换数据,需求表中有PrimaryKey,
--   或者unique索引,如果数据库已经存在数据,则用新数据替换,如果没有数据效果则和insert into一样;
-- insert ignore表示,如果表中已经存在相同的记录,则忽略当前新数据;

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

SQL36 创建一个actor_name表,并且将actor表中的所有first_name以及last_name导入该表

CREATE TABLE actor_name
(
    first_name    varchar(45)    not null    comment'名字',
    last_name     varchar(45)    not null    comment'姓氏'
);

INSERT INTO actor_name
SELECT first_name,last_name FROM actor;

注:INSERT、SELECT插入查询结果

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

九号会弹钢琴啊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值