這篇文章主要介紹了MySQL怎么建立約束,具有一定借鑒價值,需要的朋友可以參考下。希望大家閱讀完這篇文章后大有收獲。下面讓小編帶著大家一起了解一下。
10余年的豐順網(wǎng)站建設(shè)經(jīng)驗,針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時及時工作處理。成都營銷網(wǎng)站建設(shè)的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整豐順建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗。創(chuàng)新互聯(lián)從事“豐順網(wǎng)站設(shè)計”,“豐順網(wǎng)站推廣”以來,每個客戶項目都認真落實執(zhí)行。
mysql建立約束的方法:1、創(chuàng)建表的時候,代碼為【constraint 索引名 foreign key(外鍵列)】;2、建表完成之后,主鍵約束【alter table table_name add primary key (字段)】。
mysql建立約束的方法:
第一種:創(chuàng)建表的時候
create table table_name( 列名1 數(shù)據(jù)類型 (int) primary key auto_increment, 列名2 數(shù)據(jù)類型 not null, 列名3 數(shù)據(jù)類型 unique, 列名4 數(shù)據(jù)類型 default '值', constraint 索引名 foreign key(外鍵列) references 主鍵表(主鍵列) on delete cascade | on delete set null )
第二種:建表完成之后
1.主鍵約束 添加:alter table table_name add primary key (字段) 刪除:alter table table_name drop primary key 2.非空約束 添加:alter table table_name modify 列名 數(shù)據(jù)類型 not null 刪除:alter table table_name modify 列名 數(shù)據(jù)類型 null 3.唯一約束 添加:alter table table_name add unique 約束名(字段) 刪除:alter table table_name drop key 約束名 4.自動增長 添加:alter table table_name modify 列名 int auto_increment 刪除:alter table table_name modify 列名 int 5.外鍵約束 添加:alter table table_name add constraint 約束名 foreign key(外鍵列) references 主鍵表(主鍵列) 刪除: 第一步:刪除外鍵 alter table table_name drop foreign key 約束名 第二步:刪除索引 alter table table_name drop index 索引名 [^1]: 約束名和索引名一樣 6.默認值 添加:alter table table_name alter 列名 set default '值' 刪除:alter table table_name alter 列名 drop default
感謝你能夠認真閱讀完這篇文章,希望小編分享mysql怎么建立約束內(nèi)容對大家有幫助,同時也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,遇到問題就找創(chuàng)新互聯(lián),詳細的解決方法等著你來學(xué)習(xí)!
文章名稱:mysql怎么建立約束
鏈接URL:http://muchs.cn/article24/pdpsce.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、營銷型網(wǎng)站建設(shè)、面包屑導(dǎo)航、網(wǎng)站維護、云服務(wù)器、Google
聲明:本網(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)