SQL Server BasicsWhat is SQL Server database?What is RDBMS?What is Normalization?Why we use Denormalization?What_is_SQL?What is PL/SQL?Difference between SQL and PL/SQLDatabase TableOne to One RelationshipOne to Many RelationshipMany to Many RelationshipMany to One RelationshipString Data TypesNumber Data TypesDate Data TypesOther Data TypesCreate DatabaseDrop DatabaseCreating and Managing Users in SQL ServerCreate TableAlter TableDrop TableConstraints in SQL serverPrimary KeyForeign KeyUnique KeyCandidate KeyComposite KeyDifference between primary key and candidate keyPrimary key and foreign key relationshipSurrogate KeyCascading Referential Integrity ConstraintsSelf Referential Integrity ConstraintsInsert into statementInsert multiple recordsUpdate statementDelete statementTruncate statementDifference between Delete and TruncateAlias in SQL ServerSelect statementSelect DistinctSelect TopSelect IntoNull Functions(ISNULL(),NULLIF(),COALESCE())Sub QueryIdentity ColumnSequence objectDifference between sequence and identity columnSQL Server ClausesWHERE ClauseOrder By ClauseTop N ClauseGroup By ClauseHaving ClauseDifference between Where and HavingSQL Server OperatorsArithmetic OperatorsComparison OperatorsLogical OperatorsBitwise OperatorsAny OperatorsAll OperatorsUnion OperatorsUnion All OperatorsDifference between Union and Union AllIntersect OperatorExcept OperatorDifference between Except and IntersectJoinsInner JoinLeft JoinRight JoinFull JoinSelf JoinCross JoinViewsWhat are views?Create views using SSMSIndexed ViewsComplex ViewsCheck Option in ViewCheck Encryption in ViewSchema Binding Option in ViewRead-only ViewsUpdatable ViewsAdvantages and disadvantages of viewsCreate multiple views on one tableCan we implement index on views?Can we Perform Insert, update, delete operation on views?Stored Procedure and FunctionsWhat are Stored Procedures?Why we use stored procedures?Passing parameters to Stored procedureUser-Defined FunctionsDifference between UDF and Stored procedurePre-Defined Functions@@Indentity and Scope_IndentityNULLIF, ISNULL and COALESCE

SQL - Many to Many Relationship

Let's consider a many-to-many relationship between "Students" and "Courses" in a university database. In this scenario, multiple students can enroll in multiple courses, and each course can have multiple students.

Here's a simplified representation of the two tables:

Table: Students
StudentID StudentName Major
1 John Doe Biology
2 Jane Smith History
3 Mark Johnson Chemistry
Table: Courses
CourseID CourseName Credits
1 Math 101 3
2 English 201 4
3 Physics 301 3
Table: Enrollment (Join Table)
StudentID CourseID
1 1
1 2
2 1
3 2
3 3

In this example, each student in the "Students" table can enroll in multiple courses, and each course in the "Courses" table can have multiple students. The "Enrollment" table serves as a join table that represents the many-to-many relationship between students and courses.

By using the join table, we establish the connections between students and courses. For example, John Doe (StudentID 1) is enrolled in both "Math 101" (CourseID 1) and "English 201" (CourseID 2). Jane Smith (StudentID 2) is enrolled in "Math 101," and Mark Johnson (StudentID 3) is enrolled in both "English 201" and "Physics 301."

This many-to-many relationship allows for flexible enrollment of students in various courses and ensures that each course can have multiple students, and each student can enroll in multiple courses.

Many-to-many relationships are commonly used in various database scenarios, such as student-course enrollment, where multiple students can be enrolled in multiple courses, or product-order systems, where multiple products can be associated with multiple orders.