zoukankan      html  css  js  c++  java
  • 添加索引,联合唯一索引

    1.UNIQUE 关键字建唯一索引
    mysql> CREATE TABLE `wb_blog` (
    -> `id` smallint(8) unsigned NOT NULL,
    -> `catid` smallint(5) unsigned NOT NULL DEFAULT '0',
    -> `title` varchar(80) NOT NULL DEFAULT '',
    -> `content` text NOT NULL,
    -> PRIMARY KEY (`id`),
    -> UNIQUE KEY `catename` (`catid`)
    -> ) ;
    如果建好表了,可以用以下语句建
    mysql> CREATE UNIQUE INDEX catename ON wb_blog(catid);

    2.联合索引
    ALTER TABLE `tasks`
    ADD INDEX `testabc` (`title`, `created`) ;

    3联合唯一索引(假设有这个需求,在同一天内不能建两个tiltle一样的任务)
    ALTER TABLE `tasks`
    ADD UNIQUE INDEX `testabc` (`title`, `created`) ;

    数据库建索引的科学性事关数据库性能,索引也不是越多越好。
  • 相关阅读:
    Binary Tree Paths
    Implement Stack using Queues
    Path Sum II
    Path Sum
    Plus One
    Add Digits
    Missing Number
    H-Index II
    H-Index
    Ugly Number II
  • 原文地址:https://www.cnblogs.com/jinshuo/p/8624467.html
Copyright © 2011-2022 走看看