MySQL: how to do row-level security (like Oracle's Virtual Private Database)?

后端 未结 3 2265
梦毁少年i
梦毁少年i 2020-12-11 21:55

Say that I have vendors selling various products. So, at a basic level, I will have the following tables: vendor, product, vendor_product

3条回答
  •  余生分开走
    2020-12-11 22:24

    This sounds to me that you want to normalize your data. What you have is a 1 (product) to many (vendors) relationship. That the relationship is 1:1 for most cases and only 1:n for some doesn't really matter I would say - in general terms it's still 1:n and therefor you should design your database this way. The basic layout would probably be this:

    Vendor Table
    VendorId    VendorName    OtherVendorRelatedInformation
    
    WidgetTable
    WidgetId    WidgetName    WidgetFlag     CreatorVendor   OtherWidgetInformation
    
    WidgetOwnerships
    VendorId    WidgetId      OwnershipStatus     OtherInformation
    

    Update: The question of who is allowed to do what is a business problem so you need to have all the rules laid out. In the above structure you can flag which vendor created the widget. And in the ownership you can flag what the status of the ownership is, for example

    • CreatorFullOwnership
    • SharedOwnership
    • ...

    You would have to make up the flags based on your business rules and then design the business logic and data access part accordingly.

提交回复
热议问题