SQL Server中多對多關係的實現

來源:互聯網
上載者:User

標籤:

多對多的關係必須另外添加一張表來表示

--班級create table banji(banji_id int constraint PK_banji primary key,  --主鍵banji_num int not null,banji_name nvarchar(20) )--教師create table jiaoshi(jiaoshi_id int constraint PK_jaioshi primary key,  --主鍵jiaoshi_name nvarchar(20) not null)--班級和教師的關係create table banji_jiaoshi_mapping(banji_id int constraint FK_bnaji_id foreign key references banji(banji_id),    --外鍵jiaoshi_id int constraint FK_jaoshi_id foreign key references jiaoshi(jiaoshi_id),   --外鍵kecheng nvarchar(20),constraint PK_banji_id_jiaoshi_id primary key (banji_id, jiaoshi_id, kecheng)    --benji_id, jiaoshi_id, kecheng的三者組合作為主鍵)

 

資料庫圖表:

 

SQL Server中多對多關係的實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.