当前位置: 代码迷 >> SQL >> SQL3范式以及数据模式
  详细解决方案

SQL3范式以及数据模式

热度:12   发布时间:2016-05-05 14:44:31.0
SQL三范式以及数据模式

三范式

  第一范式,1NF:(1).数据列只包含有原子性的值
    (2).没有重复的数据组

   第二范式,2NF:(1)符合第一范式
(2)没有部分函数依赖  (如果location和weather是组合主键,temperature都不是主键,weather改变会引起temperature改变,location改变不会引起temperature改变,
则称temperature对主键有部分依赖)

   第三范式,3NF:(1)符合第二范式
(2)没有传递函数依赖性 (如果weather和temperature都不是主键,但是但weather改变会引起temperature改变时,称两者具有传递函数依赖性)


数据模式

1.一对多关系:如表 person (person_id Primary Key, name, nationality, interest)
      则称nationality和person_id具有一对多关系,因为每一个nationality可能对应多个person_id,但每个person_id只有一个nationality
      此时,将nationality抽取出来,创建表nationality_table ( nationality_id Primary Key, nationality)
      将person表改为 person (person_id PK, name, nationality_id Foreign Key, interest)


2.多对对关系:如表 person (person_id Primary Key, name, nationality, interest)
      则称interest和person_id具有多对多关系,因为每个interest对应多个person_id,而每个person_id对应多个interest
      此时将interest抽取出来,创建新标 interest_table (interest_id PK, interest)
      原person表改为person (person_id Primary Key, name, nationality, interest_id)
      并创建 junction table(连接表)  person_interest (person_id FK, interest_id, FK),用于连接person和interest_table两表