2012-04-09 42 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 

試試這個