如何保存相关记录 [英] How to save associated Records

查看:68
本文介绍了如何保存相关记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,我正在开发一个网络应用程序我有用户,用户有以下信息

用户(ID(P),姓名,电子邮件,密码,SecutiryQuestion,SecurityANswer,区, TEhsil,UCS,村庄)



现在所有其他信息都比较简单,但是地区,tehsil,ucs,村庄是级联性质意味着一个地区可以拥有许多Tehsil ,一个tehsil可以有很多UCS,一个ucs可以有许多村庄,它们是级联性质的,

我已经为所有这些项目放置了checkboxlist项目,并且首先为区域创建了四个表格(Districtid(P) ,DistrictName)

Tehsil(TehsilID(P),TEhsilName,DistrictID(F))

UC(UCID(P),UCNAME,TehsilID(F))

VILAGES(VILLAGEIF(P),VIllageNAme,UCID(F))

我根据复选框列表值选择填充它们现在为了保存单个用户我有这些规则

1 - 一个用户必须拥有一个或多个区域

2 - 一个用户可以没有或多个TEhsils

3 - 一个用户可以没有或很多UCs

4 - 一个用户可以没有或很多村庄



对于用户信息,我创建了一个表(用户ID(P),名称,电子邮件,密码,SecurityQuestion,SecurityAnswer,DistrictID)



和另一个详细信息表,其中我有用户ID作为外键

UserDetails(用户ID(F),RecordID(P),Districtid(F),(TEHSILID(F),UCID(F),VIllageID(F))





告诉我这个结构适合在编辑时插入和显示checkbos列表或者不是

Dear , I am developing a web application In which i have users , the user have the following information
User(ID(P),Name,EMail,Password,SecutiryQuestion,SecurityANswer,District,TEhsil,UCS,Villages)

Now All other infromation is simpler one but the district ,tehsil,ucs,villages are cascade in nature mean that one district can have many Tehsil,one tehsil can have many UCS, and one ucs can have many villages they are cascade in nature ,
I have placed checkboxlist item for all of them and created four tables first for district(Districtid(P),DistrictName)
Tehsil(TehsilID(P),TEhsilName,DistrictID(F))
UC(UCID(P),UCNAME,TehsilID(F))
VILAGES(VILLAGEIF(P),VIllageNAme,UCID(F))
and i am populating them based on there checkboxlist value selection Now for saving a single user i have these rules
1-One user must have one or more districts
2-one user can have no or many TEhsils
3-One user can have no or many UCs
4-One user can have no or many Village

For user information I have created a table (userid(P),Name,EMail,Password,SecurityQuestion,SecurityAnswer,DistrictID)

and another details table where i have userid as foreign key
UserDetails(Userid(F),RecordID(P),Districtid(F),(TEHSILID(F),UCID(F),VIllageID(F))


tell me this structure is good for inserting and showing checkbos list on edit as well or not

推荐答案

这似乎没关系,但我想指出你的方向不同。如何制作一个名为Region的单个表,它将保存整个层次结构(zone,tehsil,UC,Village)。例如Region(Region_ID,Parent_Region_ID,RegionName,IsTehsil,IsUC,IsVillage,IsDistrict等)



让我们假设你有以下结构



Region_Id - > Parent_region_id - > Region_Name

1 - > NULL - > Root

2 - > 1 - >卡拉奇

3 - > 2 - >卡拉奇Tehsil 1

4 - > 3 - >卡拉奇Tehsil 1 UC 1

5 - > 4 - >卡拉奇Tehsil 1 UC 1 Village 1



这可以继续下去。这将有助于您更自然,更优雅地保护结构。对于用户表,您可以修改您的用户详细信息表如下



User_Detail(Record_ID,User_ID,ASSOCIATED_REGION_ID(FK REGION_ID))。为了理解目的,我们假设您有一个仅与区域相关联的用户ACME。



为此,您将按如下方式分配给他

Record_id - > User_Id - > Associated_Region_ID

1 - > 1(ACME) - > 2(卡拉奇)



同样,您可以将此用户分配到村级以及如下所示

Record_id - > User_Id - > Associated_Region_ID

1 - > 1(ACME) - > 5(村1)



由于保留了层次结构,您可以轻松地将层次结构分配给任何用户。



希望这可以帮助你做出好的设计
This seems okay, but i like to point you in a different direction. How about making a single table named Region which will hold the whole hierarchy that is (district, tehsil, UC, Village). For example Region(Region_ID, Parent_Region_ID, RegionName, IsTehsil, IsUC, IsVillage, IsDistrict, etc)

Lets assume you have following structure

Region_Id -> Parent_region_id -> Region_Name
1 ->NULL -> Root
2 ->1 -> Karachi
3 ->2 -> Karachi Tehsil 1
4 ->3 -> Karachi Tehsil 1 UC 1
5 ->4 -> Karachi Tehsil 1 UC 1 Village 1

and this can go on and on. This will help you preserve the structure more naturally and elegantly. For User Table you can modify your user detail table as follow

User_Detail(Record_ID, User_ID, ASSOCIATED_REGION_ID (FK REGION_ID)). For understanding purpose lets say you have a user ACME which is associated with District only.

For this purpose you will assign him as follows
Record_id -> User_Id -> Associated_Region_ID
1 -> 1 (ACME) -> 2 (karachi)

Similarly you can assign this user to village level as well like below
Record_id -> User_Id -> Associated_Region_ID
1 -> 1 (ACME) -> 5 (Village 1)

Since the hierarchy is preserved you can easily assign the hierarchy to any user.

Hopes this help you make a good design


这篇关于如何保存相关记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆