mysql資料庫學習——4,完整性條件約束

來源:互聯網
上載者:User
主鍵create table feng(

teamno int not null,playerno int not null,division char(6) not null,primary key(teamno))  

create table feng(

teamno int not null primary key ,playerno int not null,division char(6) not null,) 複合主鍵create table feng(

teamno int not null,playerno int not null,division char(6) not null,primary key(teamno,playerno)) 替代鍵(候選索引鍵) create table feng(

teamno int not null primary key ,playerno int not null,division char(6) not null,unique(playerno)) create table feng(

teamno int not null primary key ,playerno int not null,division char(6) not null,unique(playerno,division)) 外鍵(在innoDB中使用)外鍵聲明包括三個部分1,那個列或列組合是外鍵2,指定外鍵參照的表和列3,參照動作[cascade(級聯操作),restrict(拒絕操作),set null(設為空白),no action,set default]如果沒有指定參照動作預設是on update restricton delete  restrictcreate table feng(

teamno int not null primary key ,playerno int not null,division char(6) not null,foreign key(division)references othertable   (column)on update restrictunique(playerno)) check完整性條件約束create  table players (playerno int not null, sex   char(1) not null,         check (sex in ('m','f'))) create  table players (playerno int not null,birth_date  date, sex   char(1) not null,         check (sex in ('m','f'))joined smallint not null,             check (year(birth_date)<joined),             check (joined<1880),) create  table players (playerno int not null,birth_date  date, sex   char(1) not null,          check (sex in (select sex from wholetab))
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.