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'