簡體   English   中英

映射表時,將數據輸入小型數據庫的最佳方法是什么?

[英]What is the best way to enter data into a small database when mapping tables?

我有一個小問題,我相信你們那里所有聰明的人都已經有一個簡單的解決方案。 我只是還沒有意識到。

我是一個項目的設計師,在這項工作中,我依賴於PostgreSQL數據庫,因此我有一個事實版本。 我使用常見做法來設置表,例如為每個表使用PK(序列)。 當我將兩個表鏈接在一起時,我將使用外鍵。 這極大地幫助了我檢查設計並做出報告。

以以下三個表(每個表一個字段)為例:

student_id : student_name
1          : j bloggs

class_id   : class_name
1          : physics

student_class_assoc : student_id : class_id
1                   : 1          : 1

我可以使用PGAdmin為學生和班級輸入數據,這沒問題,但是在將學生和班級聯系在一起時,我必須轉到每個表並找到ID。 在這種情況下,這是微不足道的,但是當我有大約70或80個條目時,就會變得很麻煩。 理想情況下,我希望能夠通過搜索student_name和class_name字段,然后輸入相關ID來輸入數據。

我曾考慮過使用簡單的PHP表單來執行此操作,但我想我會首先請其他人看看是否有更好的解決方案。

最好的祝福,

亞當

假設student_class_assoc是一個序列

insert into student_class_assoc (student_id, class_id)
select student_id, class_id
from
    (values
        ('j bloggs', 'physics'),
        ('m mary', 'math')
    ) a (student_name, class_name)
    inner join
    student using (student_name)
    inner join
    class using (class_name)

但是存在通用名稱的問題。 如果有兩個m mary他們都會在math課上。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM