2012-08-09 67 views
1

首先感謝您停下來閱讀此問題。 所以這是我的問題。 我有MySQL中的表名爲tbl_section,其中核心領域應該是:使用多個值創建字段

  • SECTION_ID
  • SECTION_NAME
  • adviser_id
  • student_id數據

所以這裏的交易有可能是1部分有多個student_id,如果有的話我應該怎麼做呢?我試過尋找數據類型枚舉來解決這個困境,但我得到的所有 什麼也沒有。

希望你們有這個解決方案。 謝謝您的閱讀! 誰會解決這個問題,我會把他的雕像,像上帝一樣放在我的前院!

+0

爲什麼不只是有多行而不必在一個罪惡中存儲和管理多個ID gle領域。 – ChrisBint 2012-08-09 04:36:57

+2

如何創建另一個表,其中student_id是主鍵,section_id是外鍵? – Gnijuohz 2012-08-09 04:37:15

回答

3

是的,你需要主從表或1到N的關係表 即

create table section (
    section_id int, 
    section_name varchar(100), 
    adviser_id -- don't know what this field mean 
) 
create table student (
    section_id int, 
    student_id int, 
    student_name varchar(200) 
) 

那麼你可能不喜歡這樣

insert into section (1, 'section1', 0) 
insert into student (1,10,'John Gordon') 
insert into student (1,11,'Shor Khan') 

那麼你就可以得到所有學生SECTION1

select * from student where section_id = 1 
相關問題