2012-04-09 41 views
-1

我有三张桌子。这些设计就像我怎样才能使这张桌子的意见?

学生表

create table student (studID int not null primary key AUTO_INCREMENT, 
StudName varchar(20), 
Parent varchar(20), 
PhoneNo int not null 
) 

课程表的设计

create table Course (CID int not null primary key AUTO_INCREMENT, 
CName varchar(20)) 

studCourse表设计

create table studCourse(studID int not null 
,CID int not null 
) 

我怎样才能使这显示学生的姓名和视图他正在学习的课程是什么?

回答

0

您可以从查询创建连接的视图,这样的事情应该工作:

CREATE VIEW v AS (
SELECT s.StudName AS student,c.CName AS course 
FROM student s 
JOIN studCourse d USING(studID) 
JOIN Course c ON (d.CID = c.CID) 
) 
0
CREATE VIEW vwStudent AS 
     SELECT 
     s.StudName, 
     c.CName 
    FROM student s 
     INNER JOIN studCourse sc 
     ON s.studID = sc.studID 
     INNER JOIN Course c 
     ON c.CID = sc.CID 

CREATE VIEW vwStudent AS 

    SELECT 
      s.StudName, 
      c.CName 
     FROM student s 
      JOIN studCourse sc 
      ON s.studID = sc.studID 
      JOIN Course c 
      ON c.CID = sc.CID 

试试这个