2021-09-18牛客SQL32,SQL33,SQL35,SQL36,SQL37,SQL38,SQL40

SQL32.sql字符串拼接(concat函数):
将employees表的所有员工的last_name和first_name拼接起来作为Name,中间以一个空格区分
(注:sqllite,字符串拼接为 || 符号,不支持concat函数,mysql支持concat函数)

select concat(last_name,' ',first_name) as name from employees

//concat函数在sql语法中是做字符串拼接的;

SQL33.创建表及字段:

create table actor (actor_id int(5) primary key,
                     first_name varchar(45) not null,
                     last_name varchar(45) not null,
                     last_update date not null)

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

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

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

create table if not exists actor_name(
first_name  varchar(45)  not null,
last_name   varchar(45)  not null);

insert into actor_name
(select first_name, last_name from actor);

SQL37.对first_name创建唯一索引uniq_idx_firstname,对last_name创建普通索引idx_lastname;

create index idx_lastname on actor(last_name);
create unique index uniq_idx_firstname on actor(first_name);

SQL38.针对actor表创建视图actor_name_view,只包含first_name以及last_name两列,并对这两列重新命名

create view actor_name_view as
select first_name as first_name_v, last_name as last_name_v
from actor;

//创建视图
create view actor_name_view as
select first_name first_name_v, last_name last_name_v from actor;

//使用视图
select * from actor_name_view;

SQL40.在last_update后面新增加一列名字为create_date, 类型为datetime, NOT NULL,默认值为’2020-10-01 00:00:00’

alter table actor add create_date datetime not null
default '2020-10-01 00:00:00'
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值