• Abby

    your notation is rather strange, I can't follow it, so I can't see what's giving an error.

    However, your text seems to indicate what you are trying to do and it is pretty straightforward. Some SQL is given below which creates the tables and the relationships between them, but no columns other than columns involved in primary or foreign keys (you'll need to add those, where they should go is commented). I've left out indexes other than needed to support primary key. I've also left out the surrogate key permID because it seems a superfluous complication; but it's easy to add if you must.

    Of course because I'm working from a brief text description rather than something more specific (as indicated by Craig in his message above) this may not actually be what you want.

    create table operation (

    opID int primary key

    -- ,other columns

    )

    create table object (

    objID int primary key

    -- ,other columns

    )

    create table permission (

    objID int not null references object(objID)

    ,opID int not null references operation(opID)

    -- ,other columns if any

    ,primary key(objID,opID)

    )

    create table role (

    roleID int primary key

    -- ,other columns

    )

    create table rolepermission (

    roleID int not null references role(roleID)

    ,objID int not null

    ,opID int not null

    -- ,other columns if any

    ,primary key (roleID,objID,opID)

    ,foreign key (objID,opID) references permission(objID,opID)

    )

    -- drop table rolepermission, permission, object, operation, role

    Tom