现在,我有一张桌子:

Id  -  CollegeName   -   CourseName

这张桌子没有标准化,所以我每1所大学都有很多 class
我需要将其标准化为两个表:
Colleges:  CollegeID  -  CollegeName
Courses:   CourseID  - CollegeID  - CourseName

是否有捷径可寻?
谢谢

最佳答案

如果您使用Colleges.CollegeID和Courses.CourseID作为自动编号的字段创建2个新表,则可以使用:

INSERT INTO Colleges (CollegeName)
  SELECT DISTINCT CollegeName
    FROM OLdTable ;

INSERT INTO Courses (CollegeID, CourseName)
  SELECT Colleges.CollegeID, OldTable.CourseName
    FROM OldTable
      JOIN Colleges
        ON OldTable.CollegeName = Colleges.CollegeName ;

关于sql - SQL规范化,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4642618/

10-11 07:12