-6

I have two tables named student_table(student_id,student_name),teacher_table(teacher_id,teacher_name). Now I want to create a relational table named teacher_student_table which column will be (id,student_id,teacher_id). In student_table field named student_id is auto increment and in teacher_table field named teacher_id is auto increment.

And in teacher_student_table field named id is also auto_increment.Now how I can make this type of relational table? need help. I don't know how to create this in sql(wamp localhost)

4

2 回答 2

2

You also want to have foreign-keys to the other tables.

CREATE TABLE teacher_student_table
(
id int NOT NULL AUTO_INCREMENT,
student_id int NOT NULL,
teacher_id int NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (student_id) REFERENCES student_table(student_id),
FOREIGN KEY (teacher_id) REFERENCES teacher_table(teacher_id)
)
于 2013-11-07T08:46:54.833 回答
1

这是非常基本的 SQL,您应该可以轻松地在您的课程文献中查找它。

CREATE TABLE teacher_student_table
(
id int NOT NULL AUTO_INCREMENT,
student_id int NOT NULL,
teacher_id int NOT NULL,
PRIMARY KEY (ID)
FOREIGN KEY (student_id) REFERENCES student_table(student_id),
FOREIGN KEY (teacher_id) REFERENCES teacher_table(teacher_id)
)
于 2013-11-07T08:38:14.243 回答