Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 第一个数据库:我的表结构看起来如何?_Sql_Database_Relational Database - Fatal编程技术网

Sql 第一个数据库:我的表结构看起来如何?

Sql 第一个数据库:我的表结构看起来如何?,sql,database,relational-database,Sql,Database,Relational Database,我正在创建我的第一个数据库,以帮助我为即将开始的直销活动组织我的潜在客户。我对创建数据库了解不多,但请查看我当前的设置并提供反馈 我有三个父表: LeadHeader MailHeader Campaign 我有三个子表: LeadDetails MailDetails CampaignDetails 这是我的桌子: 领先者 Guid (Unqiue identifier) LeadType (Bankruptcy, NOO OOS, Empty Nesters, inheritance)

我正在创建我的第一个数据库,以帮助我为即将开始的直销活动组织我的潜在客户。我对创建数据库了解不多,但请查看我当前的设置并提供反馈

我有三个父表:

LeadHeader
MailHeader
Campaign
我有三个子表:

LeadDetails
MailDetails
CampaignDetails
这是我的桌子:

领先者

Guid (Unqiue identifier)
LeadType (Bankruptcy, NOO OOS, Empty Nesters, inheritance)
LeadSource (Driving For Dollars, Cold Calling, ListSource)
FirstName
LastName
Street
HouseNumber
City
State
Phone
MailingInd (Y/N)
CampaignName (Name of campaign from the MailHeader table)
ResponseInd (Y/N)
AppointmentInd (Y/N)
AcceptedOfferInd (Y/N)
Guid (Unqiue identifier)
CampaignName (Name of campaign from the MailHeader table)
CampaignStartDate
CampaignEndDate 
NumberOfMailings (Total number of mailings)
ResponseIND
LeadDetail

Guid (Unqiue identifier)
ParentLeadGuid (Links to the Parent Table LEADERHEADER)
Year Built
Purchase Date
Bedrooms
Bathrooms
AssessedValue
Response
Response Date
Notes
ParentGuid (Links to the Parent Table MailHeader)
Guid (Unqiue identifier)
MailingNumber (1st,2nd,3rd,4th,ect)
MailingDate (**/**/****)
MailType (Postcard, Letter)
MailMessage
ResponseID (Unqiue identifier for responses since there can be multiple)
Response (Message of response)
邮件标题

Guid (Unqiue identifier)
LeadType (Bankruptcy, NOO OOS, Empty Nesters, inheritance)
LeadSource (Driving For Dollars, Cold Calling, ListSource)
FirstName
LastName
Street
HouseNumber
City
State
Phone
MailingInd (Y/N)
CampaignName (Name of campaign from the MailHeader table)
ResponseInd (Y/N)
AppointmentInd (Y/N)
AcceptedOfferInd (Y/N)
Guid (Unqiue identifier)
CampaignName (Name of campaign from the MailHeader table)
CampaignStartDate
CampaignEndDate 
NumberOfMailings (Total number of mailings)
ResponseIND
邮件详细信息

Guid (Unqiue identifier)
ParentLeadGuid (Links to the Parent Table LEADERHEADER)
Year Built
Purchase Date
Bedrooms
Bathrooms
AssessedValue
Response
Response Date
Notes
ParentGuid (Links to the Parent Table MailHeader)
Guid (Unqiue identifier)
MailingNumber (1st,2nd,3rd,4th,ect)
MailingDate (**/**/****)
MailType (Postcard, Letter)
MailMessage
ResponseID (Unqiue identifier for responses since there can be multiple)
Response (Message of response)
活动

Guid (Unqiue identifier)
CampaignName
CampaignStartDate
CampaignEndDate
NumberofLeadsMailed
NumberofCallsReceived
AcceptedOfferInd (Y/N)
AcceptedOfferNumber (7)
AppointmentInd (Y/N)
ApointmentNumber (20)
CampaignID GUID PK
CampaignName varchar(50)
CampaignStartDate date
CampaignEndDate date
NumberofLeadsMailed smallint
NumberofCallsReceived smallint
AcceptedOfferInd bit
AcceptedOfferNumber smallint
AppointmentInd bit  ?? 
ApointmentNumber smallint  ??
活动详情

Guid (Unqiue identifier)
ParentGuid (Links to the Parent Table Campaign)
PositiveCalls (Leads to in person meeting)
NetrualCalls (Inquiring Information but not meeting. Not angry)
NegativeCalls (People who don't want to be contacted)
AppointmentID
ApointmentNotes
AcceptedOfferID
AcceptedOfferNotes

谢谢你的反馈

您的目标基本上是不重复输入信息,这样当您更改某些内容(如活动名称)时,您就不必在使用该名称的任何地方都更改它

也就是说,如果不知道您的实际数据是什么样的,我的建议将有点有限,并且可能不适用。然而,为了实现上述目标,我会做一些更改

首先,我将创建以下“子”表:

LeadType

LeadTypeID int PK
LeadTypeDescription varchar(50)
_With data:_
1 'Bankruptcy'
2 'NOO OOS'
3 'Empty Nesters'
4 'Inheritance'
LeadSourceID int PK
LeadSourceDescription varchar(50)
_With data:_
1 'Driving For Dollars'
2 'Cold Calling'
3 'ListSource'
LeadSource

LeadTypeID int PK
LeadTypeDescription varchar(50)
_With data:_
1 'Bankruptcy'
2 'NOO OOS'
3 'Empty Nesters'
4 'Inheritance'
LeadSourceID int PK
LeadSourceDescription varchar(50)
_With data:_
1 'Driving For Dollars'
2 'Cold Calling'
3 'ListSource'
活动

Guid (Unqiue identifier)
CampaignName
CampaignStartDate
CampaignEndDate
NumberofLeadsMailed
NumberofCallsReceived
AcceptedOfferInd (Y/N)
AcceptedOfferNumber (7)
AppointmentInd (Y/N)
ApointmentNumber (20)
CampaignID GUID PK
CampaignName varchar(50)
CampaignStartDate date
CampaignEndDate date
NumberofLeadsMailed smallint
NumberofCallsReceived smallint
AcceptedOfferInd bit
AcceptedOfferNumber smallint
AppointmentInd bit  ?? 
ApointmentNumber smallint  ??
然后使用对这些表的引用来代替原始表中的引用。ie
LeadHeader.CampaignName
这看起来像是您在
Campaign
表中想要的,它只需要包含与该活动相关的所有信息(根据需要提供适当的链接),然后只需从该表中引用
GUID

其次,确保在输入记录时不必复制任何其他信息。例如,如果您可以为一个活动安排多个约会,您可能需要一个单独的
约会
表,其中包含相关数据

第三,我不知道您使用的是什么数据库,但请确保列的数据类型是适当的。是/否是
布尔值
。保存地址的字段不需要是10个字符。
char
数据类型是固定宽度,而
varchar
数据类型是可变长度。考虑您将拥有多少数据,以及您可以分配多少空间给该数据库。根据您拥有的数据类型,您可能必须使用
nvarchar

第四,不要对数据做太多假设。一个人的名字并不总是由字符组成“约翰·史密斯”和“约翰·奥史密斯”一样有效,也和“约翰·奥史密斯”一样有效。而且,你的
门牌号不一定总是一个数字。”3B号公寓是一个有效的门牌号

第五,给你的专栏留出足够的空间,但不要太多。其中一个假设是,您可能不需要
FirstName
字段
varchar(max)
,甚至可能不需要
varchar(1000)
。你必须根据你的预期用途来判断什么是合适的

第六,你不一定要提前把它准备好,但是要意识到你可能要在极端扩张或搬迁时做出的改变。如果你获得一百万新用户,你的数据库会扩展吗?如果你的系统转移到日本怎么办

第七,时间。决定你的约会从哪里开始。我的建议是使用UTC,这样您就可以从您的位置轻松计算显示。但同样,这将取决于您的数据和期望。只要确保如果你移动到另一个时区,你不会炸死自己。不要忘记节省时间或跳跃时间的怪癖。时间可能是一件令人头疼的事

在构建数据库时,还有大量其他注意事项。你的结构可能会随着你的构建而改变,甚至在你开始使用它之后

TL;DR:“数周的编程可以节省规划时间。”>