Assume that we’ve three tables
Course – table
------------------
ID | CourseName
------------------
1 | C++
2 | Java
------------------
Teacher – table
-----------------------
ID | TeacherName
-----------------------
1 | Professor 1
2 | Professor 2
-----------------------
CourseTeacher – table
----------------------------
ID | CourseID | TeacherID
----------------------------
1 | 1 | 1
2 | 1 | 2
3 | 2 | 1
4 | 2 | 2
----------------------------
Now that’s what to do as AFAK, but how to select, insert, update, delete records in such a format!
I mean, I’d use a simple “INSERT INTO … VALUES (..,..,..)” or a simple “SELECT * FROM …”
but now to retrieve the same single information I’ve to use some queries that includes the 3 tables somehow (Hint: I already use joins, but still how!!)
A select and insert SQL statement for my case would be very helpful.
I don’t use any models and this complicated stuff, I don’t know what the use of such a thing!
I’m using SQL Queries in my ADO.NET Objects and everything is working fine so far!
I’m not sure to understand what your question is …
Let’s assume that your PK in each table is automatically incremented.
To add a course :
INSERT INTO Course VALUES 'My New Course'To add a teacher :
INSERT INTO Teacher VALUES 'My New Teacher'Tu add an existing Course to an existing Teacher :
In the worst case scenario, meaning that you only know the names of the Teacher and the Course
In fact, in your application, when your user selects a Course to add to a Teacher, you should already know what the IDs are, because when you got the list containing them, you certainly have done this :
A link which may be useful if what I wrote is not :
http://www.singingeels.com/Articles/Understanding_SQL_Many_to_Many_Relationships.aspx