在企业中有一级部门和子部门比如有企划中心 和研发中心,都属于一级部门
企划中心包括设计部,企划部和编辑部,这三个属于二级部
研发中心包括delphi研发部和java研发部,这两个属于二级部门在设计部门信息表的时候,怎么处理呢?
我目前是这样设计的
一共两个表
一个表为一级部门信息表
department1:
  一级部门编号
  一级部门名department2:
  一级部门编号
  二级部门编号
  二级部门名因为有的部门没有子二级部门.各位觉得我上面的设计是不是有问题?
一个一级部门可以下辖多个二级部门,也可以没有二级部门
一个二级部门只对应一个一级部门在企业实际情况中,应该不会出现在不同的一级部门下有两个相同的二级部门名吧?怎么优化下我上面的数据库设计?或者更好的建议???
谢谢..

解决方案 »

  1.   

    举例如下:
    create table dept (
    code                 int                  not null,
    dep_code             int                  null,
    name                 char(50)             not null,
    constraint PK_DEPT primary key  (code)
    )
    goalter table dept
       add constraint FK_DEPT_RELATIONS_DEPT foreign key (dep_code)
          references dept (code)
    go
      

  2.   

    一個是部門碼表(dept_no,dept_name),主鍵為dept_no一個是職位碼表(position_no,position_name,dept_no),主鍵為position_no這兩個表的結構對整個公司的構架來說非常重要
      

  3.   

    create table #部门
    (
    dep_no numeric primary key,
    dep_name varchar(20),
    father_dep_no numeric references #部门(dep_no)
    )insert into #部门 values(1,'企划中心',null)
    insert into #部门 values(2,'研发中心',null)
    insert into #部门 values(3,'设计部',1)
    insert into #部门 values(4,'企划部',1)
    insert into #部门 values(5,'编辑部',1)
    insert into #部门 values(6,'delphi研发部',2)
    insert into #部门 values(7,'java研发部',2)
      

  4.   

    不是很明白 sdhylj(青锋-SS)的意思。。用关系模式写出来看看好吗??
      

  5.   

    create table dept (
    code int not null,
    dep_code int null,
    name char(50) not null,
    constraint PK_DEPT primary key (code)
    )
    goalter table dept
    add constraint FK_DEPT_RELATIONS_DEPT foreign key (dep_code)
    references dept (code)
    go
    ------------------
    code是部门表的主键,dept_code是个特殊的外键,是对自身主键(code)的引用,也就是说dept和它自身有一对多的关系.