sql 向表中添加键/索引

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 向表中添加键/索引相关的知识,希望对你有一定的参考价值。

\!h Add an index to an existing table:
ALTER TABLE artist ADD INDEX by_name (artist_name); -- adds key called 'by_name' to artist_name column

\!h Add a primary key:
ALTER TABLE artist ADD PRIMARY KEY (artist_id) -- adds primary key to artist_id column

\!h Remove non-primary key index:
ALTER TABLE artist DROP INDEX by_name;

\!h Remove primary key:
ALTER TABLE artist DROP PRIMARY KEY;

\!h Modify an index:
-- can't really be done, you have to drop and re-create with new specifications
-- Example: have the by_name index include only the first 10 characters of the artist_name:
ALTER TABLE artist DROP INDEX by_name;

ALTER TABLE artist ADD INDEX by_name (artist_name(10));

以上是关于sql 向表中添加键/索引的主要内容,如果未能解决你的问题,请参考以下文章

SQL Server索引总结二

每次向表中添加数据时,我是不是应该删除并重新创建表上的索引?

MySQL 数据库操作

外键以及数据库的增删改查你了解多少

sql TSQL向表中添加字段

sql向表中添加字段