开发者

Update table by two different users

I have a situation where stock quantity can be updated both from administrator and supplier, each containing two different keys adminID and supplierID.

What would be the best way to keep track of who made the update

ArticleID   Quant   DateModified   UpdatedBy  AdminID   SupplierID
-------------------------------------------------------------------
10493         -1     2011/03/18      0-2开发者_JAVA百科3        0          23
10495         -5     2011/03/18      5-0         5          0

I was thinking of using either a) column UpdatedBy or b) (columns adminID and supplierID). For a) I would not be able to check primary key, and for b) I would have to either create 0 for adminid and supplierid, or accept null values.

I would appreciate your comments.


I would choose two fields, AdminID and SupplierID with FK relation to Admin table and Supplier table.

I would also accept null values in AdminID and SupplierID because otherwise you would need to have one "dummy" Supplier row and one "dummy" Admin row to be able to have the FK in place.

To enforce that either AdminID or SupplierID is specified you can create a check constraint.

(AdminID is not null or SupplierID is not null)


You only want 1 column UpdatedBy. I would make the schema

Article(ArticleID, Quant, DateModified, UpdatedBy references User(UserId))
User(UserId, UserType references UserType(Type), UserName)
UserType(Type, TypeName, Description)

An update can only be done by one user at a time, so there is no point creating 2 fields. If you want to keep track of "History" it is possible to add an IsActive field which indicates the current version of the data.

Article(ArticleID, Quant, DateModified, IsActive, UpdatedBy references User(UserId))

If for supplier information you have a lot of properties which are not relevant for administrators you can make a SupplierInfo table with a foreign key to the User table.

SupplierInfo(UserId references User(UserId), FirstName, LastName, CompanyName, Address)

Some other things to consider are if you want to have different users for 1 supplier. To do this you changes the SupplierInfo table a bit make a mapping table between User and SupplierInfo.

SupplierInfo(SupplierId, FirstName, LastName, CompanyName, Address)
SupplierContacts(SupplierId references SupplierInfo(SupplierId), UserID references User(UserId))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜