Score
0
Watch 44 Star 256 Fork 69

xuthus / 数据库SQL实战SQLMIT

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or download
37.对first_name创建唯一索引uniq_idx_firstname.md 807 Bytes
Copy Edit Web IDE Raw Blame History
xuthus authored 2019-08-12 23:23 . add:all

对first_name创建唯一索引uniq_idx_firstname

题目描述

针对如下表actor结构创建索引:

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')))

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

答案

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

题解

对于SQLite和MySQL答案通用,但是对于MySQL仍然可以使用alter来进行索引的创建。

alter table actor add unique index uniq_idx_firstname (first_name),add index idx_lastname (last_name)

Comment ( 0 )

Sign in for post a comment