create index 与 alter table add index 区别

众所周知,MySQL创建索引有两种语法,即:
ALTER TABLE HeadOfState ADD INDEX (LastName, FirstName);
CREATE INDEX index_name HeadOfState (LastName, FirstName);
那么,这两种语法有什么区别呢? 
在网上找了一下,在一个英文网站上,总结了下面几个区别,我翻译出来,如下:
1、CREATE INDEX必须提供索引名,对于ALTER TABLE,将会自动创建,如果你不提供;
2、CREATE INDEX一个语句一次只能建立一个索引,ALTER TABLE可以在一个语句建立多个,如:
      ALTER TABLE HeadOfState ADD PRIMARY KEY (ID), ADD INDEX (LastName,FirstName);
3、只有ALTER TABLE 才能创建主键,ADD INDEX 不能;

时间: 2024-12-22 05:06:12

create index 与 alter table add index 区别的相关文章

【总结】alter table *** add constraint *** 用法

1. 主键约束 要对一个列加主键约束的话,这列就必须要满足的条件就是非空.因为主键约束:就是对一个列进行了约束,约束为(非空.不重复). [格式]alter table 表格名称 add constraint 约束名称 增加的约束类型 (列名) 例子:要对一个列加主键,列名为id,表名为emp alter table emp add constraint ppp primary key (id) 2. check约束就是给一列的数据进行了限制 [格式]alter table 表名称 add co

alter table *** add constraint *** 用法

1.主键约束:要对一个列加主键约束的话,这列就必须要满足的条件就是分空因为主键约束:就是对一个列进行了约束,约束为(非空.不重复)以下是代码   要对一个列加主键,列名为id,表名为emp格式为:alter table 表格名称 add constraint 约束名称 增加的约束类型 (列名)例子:alter table emp add constraint ppp primary key (id)--------------------------------2.check约束:就是给一列的数

faster alter table add column

Create a new table (using the structure of the current table) with the new column(s) included. execute a INSERT INTO new_table SELECT (column1,..columnN) FROM current_table; rename the current table rename the new table using the name of the current

[Hive - LanguageManual] Alter Table/Partition/Column

Alter Table/Partition/Column Alter Table Rename Table Alter Table Properties Alter Table Comment Add SerDe Properties Alter Table Storage Properties Additional Alter Table Statements Alter Partition Add Partitions Dynamic Partitions Rename Partition

遇到ORA-14047: ALTER TABLE|INDEX RENAME may not be combined with other operations错误

[[email protected] ~]$ sqlplus lc0029999/aaaaaa SQL*Plus: Release 11.2.0.4.0 Production on Wed Jun 10 00:11:32 2015 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit

ALTER TABLE SWITCH' statement failed. The table x' is partitioned while index 'x' is not partitioned.

1.L_Monitoring有这么些字段,ID,Collecttime,PlateType,PlateNO以及其他一些这段.建立这个表的时候是个非分区表,其中ID是主键,并在Collecttime,PlateType,PlateNO上面建立了索引. 2.系统运行一阵子后,L_Monitoring数据变得非常大,5,6千万,而且后续还会更大.所以要求将L_Monitoring表进行分区.分区方案是按照Collecttime进行每天分区.Collecttime为分区字段,并将Collecttime字

MYSQL的索引类型:PRIMARY, INDEX,UNIQUE,FULLTEXT,SPAIAL 有什么区别?各适用于什么场合?

一.介绍一下索引的类型 Mysql常见索引有:主键索引.唯一索引.普通索引.全文索引.组合索引PRIMARY KEY(主键索引) ALTER TABLE `table_name` ADD PRIMARY KEY ( `column` ) UNIQUE(唯一索引) ALTER TABLE `table_name` ADD UNIQUE (`column`)INDEX(普通索引)      ALTER TABLE `table_name` ADD INDEX index_name ( `column

index rebuild和rebuild online的区别

曾经看到过淘宝的这个面试题:在一个24*7的应用上,需要把一个访问量很大的1000万以上数据级别的表的普通索引(a,b)修改成唯一约束(a,b,c),你一般会选择怎么做,请说出具体的操作步骤与语句. 先online建索引添加约束,然后删除原理的索引. create index idx_test_abc on w_1 (a,b,c) online ; alter table test add constraint uni1 unique (a,b,c) novalidate; drop index

转:Sql Server中的表访问方式Table Scan, Index Scan, Index Seek

0.参考文献 Table Scan, Index Scan, Index Seek SQL SERVER – Index Seek vs. Index Scan – Diffefence and Usage – A Simple Note oracle表访问方式 Index Seek和Index Scan的区别以及适用情况 1.oracle中的表访问方式 在oracle中有表访问方式的说法,访问表中的数据主要通过三种方式进行访问: 全表扫描(full table scan),直接访问数据页,查找