i'm working on project , i'm new both web apps , sql, bear me. i'm building api , want make sure users have access rows in specific table have foreign key customer id in table, have validated user id in table. (a single customer has multiple users , owns multiple assets. right now, of customer's users can access asset, no customers share asset or user.) way can think
select * [asset] id=@assetid , customerid=(select customerid [user] userid=@userid); this great, many entries in asset , user tables, query take ton of time. bad since every request made api needs asset data should doing check. set index, , in fact userid secondary key in user because it's unique identifier auth provider, i'm not sure if should add index customerid in asset. asset table should grow relatively compared other tables (have messaging record table auditing purposes), i'm not sure if that's right answer, or if there's simpler answer that's more optimized. or kind of query fast @ scale have nothing worry about?
for particular case, looks perfect context build junction table between user table , asset table. both field become primary key. individually, assetid , userid foreign keys.
let's junction table called assetuser.
foreign keys :
constraint [fk_assetuser_user] foreign key ([userid]) references [user]([userid]) constraint [fk_assetuser_asset] foreign key ([assetid]) references [asset]([assetid]) primary key :
constraint [pk_assetuser] primary key([assetid], [userid])); you shouldn't worry scale unless going have alot of data and/or performance critical in application. if so, have option use hadoop or migrate nosql database.
Comments
Post a Comment