Implementation of many-to-many relationships in SQL Server

Source: Internet
Author: User

Many-to-many relationships must be added with a separate table to represent

--Class CREATE TABLE Banji (banji_id int constraint Pk_banji primary key,  --primary key banji_num int not null,banji_name nvarchar (2 0)--Teacher CREATE TABLE Jiaoshi (jiaoshi_id int constraint Pk_jaioshi primary key,  --primary key jiaoshi_name nvarchar () NOT NULL )--the relationship between class and teacher create TABLE banji_jiaoshi_mapping (banji_id int constraint fk_bnaji_id foreign key references Banji (banji_id ),    --FOREIGN key jiaoshi_id int constraint fk_jaoshi_id foreign key references Jiaoshi (jiaoshi_id),   --foreign key Kecheng nvarchar (a), constraint pk_banji_id_jiaoshi_id primary key (banji_id, jiaoshi_id, Kecheng)    --benji_id, jiaoshi_id, Kecheng three-group co-operation as the primary key)

Database diagram:

Implementation of many-to-many relationships in SQL Server

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.