数据库设计问题 [英] Database design problem
问题描述
我有一个应用程序,其中包含用户,这些用户与不同的位置相关联,这些位置是级联的,意味着他们就像州,国家,城市一样
>
我将地区作为位置,这是位置背景中的顶级实体,因此该表包含
DistrictUsers(Districtid(P),DistrictName,UserID(F) ))
下表是Tehsil意味着该区域包含Tehsil将填充的区域选择tehsil所以Tehsil表应该有区域id的forign键在其中所以
TehsilUsers(TehsilID(P),TehsilName,DistrictID(F),UserID(F))
现在选择村庄的Tehsils所以VillageUser表必须包含tehsilID作为forign键
这样
VillagesUsers(VillageID(P),VillageName,TehsilID(F),UserID(F))
和主要你服务台是
用户(用户名,(P),用户名)
P STAND FOR KEY和F FOR FOREIGN KEY
告诉我这个结构是否足够好如果没有那么建议一个表结构也让我知道如何在批量插入中保存该记录我使用相同的结构但我使用TABLE VALUE PARAMETERS for INSERT FOR FIRST TWO TABLE It Work但是当它到达第三个时它被绞死并且在循环中,同时在本地它工作正常但在服务器上它变得太慢了
Relpy任何一个
I have an application having users in it , and these users are associated with different locations , the locations are cascade in nature mean that they are like State,country,City for example
I have District as location which is the Top entity in location context so the table contains
DistrictUsers(Districtid(P),DistrictName,UserID(F))
Next table is Tehsil mean that the district contains tehsil on selection of district the Tehsils Will populates so the Tehsil table should have the forign key of District id in it so that
TehsilUsers(TehsilID(P),TehsilName,DistrictID(F),UserID(F))
Now The selection of tehsils the Village Come up so the VillageUser table must contain the tehsilID as forign key
so that
VillagesUsers(VillageID(P),VillageName,TehsilID(F),UserID(F))
and the main user table is
Users(Userid,(P),UserName)
P STAND FOR PRIMARY KEY AND F FOR FOREIGN KEY
Tell me this tructure is good enough if not then propose a table structure also let me know how to save that records in bulk insertion I am using that same structure but I am using TABLE VALUE PARAMETERS FOR INSERT FOR FIRST TWO TABLE It Work but when it reach the third it gets hanged and in loop, meanwhile locally it works fine but on server it gets too much slow
Relpy any one
推荐答案
你只能有一个表用户
以下列。另一个表UserTypes
。
表 - 用户
用户ID(P)
用户名
用户类型(F - >用户类型)
VillageID(F - >村庄)
TehsilID( F - > Tehsils)
Districtid(F - >区)
表 - 用户类型
UserTypeId( P)
UserTypeName - (例如 - DistrictUsers / TehsilUsers / VillagesUsers)
插入数据时,从前端获取数据并插入进入用户
表。
You can have only one TableUsers
with the following columns. And another Table forUserTypes
.
Table - Users
Userid (P)
UserName
UserType (F -> UserTypes)
VillageID (F -> Villages)
TehsilID (F -> Tehsils)
Districtid (F -> Districts)
Table - UserTypes
UserTypeId (P)
UserTypeName - (Ex. - DistrictUsers / TehsilUsers / VillagesUsers)
While inserting data, get the data from front end and insert intoUsers
Table.
这篇关于数据库设计问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!