天天看點

對first_name建立唯一索引uniq_idx_firstname問題描述Sql語句

sql實戰 對first_name建立唯一索引uniq_idx_firstname

  • 問題描述
  • Sql語句

問題描述

針對如下表actor結建構立索引:

(注:在 SQLite 中,除了重命名表和在已有的表中添加列,ALTER TABLE 指令不支援其他操作)

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

(請先建立唯一索引,再建立普通索引)

來源:牛客網

連結:https://www.nowcoder.com/practice/e1824daa0c49404aa602cf0cb34bdd75?tpId=82&&tqId=29805&rp=1&ru=/ta/sql&qru=/ta/sql/question-ranking

Sql語句

create (unique) index 索引名 on 表名(列名)

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