刪除主鍵時是否會刪除索引? 答案取決于索引是創(chuàng)建主鍵時自動創(chuàng)建的,還是創(chuàng)建主鍵前手工創(chuàng)建的。

創(chuàng)新互聯(lián)建站主要業(yè)務(wù)有網(wǎng)站營銷策劃、做網(wǎng)站、成都網(wǎng)站建設(shè)、微信公眾號開發(fā)、小程序制作、H5場景定制、程序開發(fā)等業(yè)務(wù)。一次合作終身朋友,是我們奉行的宗旨;我們不僅僅把客戶當(dāng)客戶,還把客戶視為我們的合作伙伴,在開展業(yè)務(wù)的過程中,公司還積累了豐富的行業(yè)經(jīng)驗、成都營銷網(wǎng)站建設(shè)資源和合作伙伴關(guān)系資源,并逐漸建立起規(guī)范的客戶服務(wù)和保障體系。
測試如下:--建表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 ==沒有刪除索引
--刪除索引,增加主鍵并自動創(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 ==自動創(chuàng)建了索引
--刪除主鍵約束
alter table hqy_test drop primary key;
select index_name from user_indexes where index_name='PK_HQY_ID';
無 ==索引被刪除了
如果刪除主鍵時,希望同時刪掉索引,則應(yīng)該增加drop index選項,從而不管索引是否是創(chuàng)建主鍵時自動創(chuàng)建的,即:alter table hqy_test drop primary key drop index;
mysql刪除表的主鍵
表結(jié)構(gòu):
create
table
service_code(
`id`
varchar(100)
NOT
NULL,
`name`
varchar(100)
NOT
NULL,
PRIMARY
KEY
(`name`)
)ENGINE=MyISAM
DEFAULT
CHARSET=gb2312;
先刪除主鍵
alter
table
service_code
drop
primary
key;
然后再添加主鍵
alter
table
service_code
add
primary
key(id);
注:在添加主鍵之前,必須先把重復(fù)的id刪除掉
先刪除自增長在刪除主鍵
Alter table tb change id id int(10);//刪除自增長
Alter table tb drop primary key;//刪除主建
網(wǎng)站題目:mysql怎么刪除主鍵6 mysql怎么刪除主鍵索引
當(dāng)前URL:http://chinadenli.net/article26/ddgcjjg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、、營銷型網(wǎng)站建設(shè)、品牌網(wǎng)站設(shè)計、App設(shè)計、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)