5
Answers

Many of u faced this problem (SQL) Many To Many Relationship

Photo of Navjot Angra

Navjot Angra

6y
678
1
I know after Reading This U will also this about it ,but if u want to know please upvote and help to me to solve
 
Suppose I have Two tables
Table A=Student
Table B=Department
 
Table A:
CREATE TABLE student
(
StudentId INT IDENTITY PRIMARY KEY,
Name VARCHAR(255),
DepartmentId VARCHAR(255),
);
INSERT INTO student VALUES ('nav',1);
INSERT INTO student VALUES ('Angra',2);
INSERT INTO student VALUES ('navjot',3);
 
 
Table B:
CREATE TABLE department
(
ID INT PRIMARY KEY,
DeptName VARCHAR(255),
studentId int unique foreign key references Student(StudentId)
);
 
INSERT INTO dbo.department VALUES (101, 'CSE', 1);
INSERT INTO dbo.department VALUES (102, 'Mech', 2);
INSERT INTO dbo.department VALUES (103, 'Civil', 1);
 
Now the Question Is :: 
Can I Insert  upper values in  Table B,I know Most of u will Say no,
but suppose  I have Rquirement To do it how it is possible  without removing Unique Constraint.
Please If Anybody have any idea ,Please share as soon as poosible 
 
Please upvote this question so that I get good answers from experts , 
 
 
 
 

Answers (5)