1. 创建一个actor表,包含如下列信息
1.1 题目描述
创建一个actor表,包含如下列信息
1.2 语句实现
create table actor (
actor_id smallint(5) not null primary key,
first_name varchar(45) not null,
last_name varchar(45) not null,
last_update date not null);
2. 批量插入数据
2.1 题目描述
题目已经先执行了如下语句:
drop table if exists actor;
CREATE TABLE actor (
actor_id smallint(5) NOT NULL PRIMARY KEY,
first_name varchar(45) NOT NULL,
last_name varchar(45) NOT NULL,
last_update DATETIME NOT NULL)请你对于表actor批量插入如下数据(不能有2条insert语句哦!)
2.2 语句实现
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');
3. 批量插入数据,如果数据已经存在,请忽略,不使用replace操作
3.1 题目描述
题目已经先执行了如下语句:
drop table if exists actor;
CREATE TABLE actor (
actor_id smallint(5) NOT NULL PRIMARY KEY,
first_name varchar(45) NOT NULL,
last_name varchar(45) NOT NULL,
last_update DATETIME NOT NULL);
insert into actor values (‘3’, ‘WD’, ‘GUINESS’, ‘2006-02-15 12:34:33’);
对于表actor插入如下数据,如果数据已经存在,请忽略(不支持使用replace操作)
3.2 语句实现
insert ignore into actor
values ('3', 'ED', 'CHASE', '2006-02-15 12:34:33');
4. 创建一个actor_name表,将actor表中的所有first_name和last_name导入该表
4.1 题目描述
对于如下表actor,其对应的数据为:
请你创建一个actor_name表,并且将actor表中的所有first_name以及last_name导入该表.
actor_name表结构如下:
4.2 语句实现
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;
5. 对first_name创建唯一索引uniq_idx_firstname,对last_name创建普通索引idx_lastname
5.1 题目描述
针对如下表actor结构创建索引:
(注:在 SQLite 中,除了重命名表和在已有的表中添加列,ALTER TABLE 命令不支持其他操作,mysql支持ALTER TABLE创建索引)
对first_name创建唯一索引uniq_idx_firstname,对last_name创建普通索引idx_lastname
5.2 语句实现
-- create unique index uniq_idx_firstname on actor (first_name);
-- create index idx_lastname on actor (last_name);
alter table actor add unique index uniq_idx_firstname (first_name);
alter table actor add index idx_lastname (last_name);
6. 针对actor表创建视图actor_name_view
6.1 题目描述
针对actor表创建视图actor_name_view,只包含first_name以及last_name两列,并对这两列重新命名,first_name为first_name_v,last_name修改为last_name_v:
6.2 语句实现
create view actor_name_view as
select first_name as first_name_v, last_name as last_name_v
from actor;