刪除主鍵時(shí)是否會(huì)刪除索引?
站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到鄠邑網(wǎng)站設(shè)計(jì)與鄠邑網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名注冊(cè)、雅安服務(wù)器托管、企業(yè)郵箱。業(yè)務(wù)覆蓋鄠邑地區(qū)。
答案取決于索引是創(chuàng)建主鍵時(shí)自動(dòng)創(chuàng)建的,還是創(chuàng)建主鍵前手工創(chuàng)建的。
測(cè)試如下:--建表create
table
hqy_test(id
integer)
;--建索引create
(unique)index
idx_hqy_id
on
hqy_test(id)
;--加主鍵alter
table
hqy_test
add
constraint
pk_hqy_id
primary
key
(id);
select
index_name
from
user_indexes
where
index_name='IDX_HQY_ID';IDX_HQY_ID
---刪除主鍵
alter
table
hqy_test
drop
constraint
pk_hqy_id;或者:alter
table
hqy_test
drop
primary
key;
也是行的。
select
index_name
from
user_indexes
where
index_name='IDX_HQY_ID';
IDX_HQY_ID
==沒(méi)有刪除索引
--刪除索引,增加主鍵并自動(dòng)創(chuàng)建索引
drop
index
idx_hqy_id;
alter
talbe
hqy_test
add
constraint
pk_hqy_id
primary
key(id)
using
index;
select
index_name
from
user_indexes
where
index_name='PK_HQY_ID';
PK_HQY_ID
==自動(dòng)創(chuàng)建了索引
--刪除主鍵約束
alter
table
hqy_test
drop
primary
key;
select
index_name
from
user_indexes
where
index_name='PK_HQY_ID';
無(wú)
==索引被刪除了
如果刪除主鍵時(shí),希望同時(shí)刪掉索引,則應(yīng)該增加drop
index選項(xiàng),從而不管索引是否是創(chuàng)建主鍵時(shí)自動(dòng)創(chuàng)建的,即:alter
table
hqy_test
drop
primary
key
drop
index;
先刪除自增長(zhǎng)在刪除主鍵
Alter table tb change id id int(10);//刪除自增長(zhǎng)
Alter table tb drop primary key;//刪除主建
在MySQL中刪除主鍵需要兩步.
1、如果有auto_increment,先刪除之;
alter table products change pid pid int;
2、刪除主鍵約束 primary key.
alter table products drop primary key;
分享名稱:mysql怎么去處主鍵 mysql如何刪除主鍵索引
分享路徑:http://muchs.cn/article6/ddceeig.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營(yíng)銷型網(wǎng)站建設(shè)、搜索引擎優(yōu)化、品牌網(wǎng)站設(shè)計(jì)、網(wǎng)站維護(hù)、網(wǎng)站建設(shè)、品牌網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)