现做的一个系统中,有很多类似的申请表,需要进行逐级审批,也就是说基层级领导审批之后,才能交给中层领导审批,中层领导审批之后,高层领导才能审批,表的相关字段如下:Create Table Users(
    Id Int Identity(0, 1) Primary Key, -- 主键
    LoginName NVarchar(20) Not Null Unique, 
    LoginPwd NVarchar(100) Not Null,
    ......
)Create Table RequestForm (
    Id Int Identity(1, 1) Primary Key,
    ......
    LevelAAgree Bit Not Null Default 0,
    LevelADate DateTime Null, 
    LevelAUserId Int Foreign Key References Users(Id) Default 0, -- 基层领导人
    LevelAContent NVarchar(200), -- 基层领导审批意见
    
    LevelBAgree Bit Not Null Default 0,
    LevelBDate DateTime Null,
    LevelBUserId Int Foreign Key References Users(Id) Default 0, -- 中层领导人
    LevelBContent NVarchar(200), -- 中层领导审批意见
    
    LevelCAgree Bit Not Null Default 0,
    LevelCDate DateTime Null,
    LevelCUserId Int Foreign Key References Users(Id) Default 0, -- 高层领导人
    LevelCContent NVarchar(200), -- 高层领导审批意见
    ......
)Go
-- 创建数据库时,在用户表中插入一个用户 EmptyUser,此用户ID等于0,专用于在其它表中表示空的引用
Insert Into Users(LoginName, LoginPwd) Values('EmptyUser', 'EmptyPassword')
当 LevelAUserId、LevelBUserId、LevelCUserId 值大于0时,分别表示基层、中层、高层领导已经审批,如果等于0,则表示该级没有审批现在需要创建一个约束,上一层的审批必须要在其下层已经做过审批的前提,也就是说 LevelBUserId > 0 的前提是 LevelAUserId > 0,并且 LevelCUserId > 0 的前提是 LevelBUserId > 0