本文介绍了数据库大小优化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个数据库,其中我有2个表。 一个表是Employees,另一个是Events。 我在Employees中只有一个字段它是EmployeeName(文本50个字符)。 事件包含字段自动编号,开始日期/时间,结束日期/时间,员工姓名。 我有员工关系员工姓名1对于许多活动。 我的问题是: 事件表中的每条记录都占用了EmployeeName的空间,还是编码为 在数据库中以另一种方式,所以它不占用EmployeeName的大小? 我如何组织我的数据库,以便它将使用最少的空间每 记录? Thanx 解决方案 空间没关系,除非你有更多的话, 文件中的100,000名员工。 然而,最好将Events表更改为包含id 而不是名称。人们的姓名确实会发生变化,而且id字段会启用 名称要更改并显示在数据库的任何位置。 对于Employees表,你需要添加一个自动编号字段作为主要的 键字段。 所以你需要: EmpID自动编号(PK) EmployeeName文本50 要更改Events表,首先需要创建一个临时表 tempEvents,其中包含EmployeeName和Empid。 创建一个maketable查询,它使用两个当前表,链接在 EmployeeName上。添加Events表中的所有字段和Empid字段 来自Employees表。 运行此查询并检查表中的一些示例值以确保 表示正确的ID与每个名称相关联。 将旧事件表重命名为OldEvents。 将tempEvents重命名为Events。 /> 从新事件表中删除员工姓名字段。 (您可能必须先删除并重新创建两个 表之间的关系 - 现在基于EmpId) 要显示没有名字的事件列表,那么你只需查看事件 表。 要显示包含名称的事件列表,您必须基于 两个表创建一个查询,包括Employees表中的名称。 回到这里发生任何问题。 问候 Peter Russell 名称将保存在每条记录中。 你可以保留一个employeeid,但这意味着修改 Employees表以添加一个id字段,然后对事件表进行一些更新以更改为id基于字段。 文件上,否则空间无关紧要。 然而,最好将Events表更改为包含id 而不是名字。人们的名字确实会发生变化,而id字段会使名称在数据库中随处可见。 对于Employees表,您需要添加一个Autonumber字段作为初级关键领域。所以你会有: EmpID自动编号(PK)员工姓名文本50 要更改事件表,首先需要创建一个包含EmployeeName和Empid的临时表 tempEvents。 创建一个maketable查询,该查询使用两个当前表,链接在EmployeeName上。从Employees表中添加Events表和Empid字段中的所有字段。运行此查询并检查表中的一些示例值,以确保正确的ID已与每个名称。 将旧事件表重命名为OldEvents。将tempEvents重命名为Events。从新事件表中删除Employee name字段。(你可能必须首先删除并重新创建两个表之间的关系 - 现在基于EmpId) 要显示没有名称的事件列表,那么你只需看一下事件表。要显示带有名称的事件列表,您必须根据两个表创建一个查询,包括Employees表中的名称。 出现的问题。 问候 Peter Russell I have a database in which I have 2 tables.One table is Employees, other is Events.I have only one field in Employees and it is EmployeeName (text 50 chars).Events has fields AutoNumber, Start Date/Time, End Date/Time, EmployeeName.I have relationships EmployeeName from Employees 1 to many for Events.My question is:Does every record in Events table take space for EmployeeName or is it codedin database in another way so it doesnt take up size of EmployeeName?How would I have to organize my database so it would use the least space perrecord?Thanx 解决方案Space doesn''t matter unless you have more than say, 100,000 employees onfile.However it would be better to change the Events table to contain an idrather than a name. People''s names do change and an id field would enablethe name to be changed and shown everywhere in the database.For the Employees table you need to add an Autonumber field as a primarykey field.So you would have:EmpID Autonumber (PK)EmployeeName Text 50To change the Events table you first need to create a temporary tabletempEvents which contains both the EmployeeName and the Empid.Create a maketable query which uses both current tables, linked onEmployeeName. Add all fields from the Events table and the Empid fieldfrom the Employees table.Run this query and check some sample values from the table to make surethat the correct ID has been associated with each name.Rename the old events table as OldEvents.Rename tempEvents to Events.Delete the Employee name field from the new Events table.(You might have to delete and re-create relationships between the twotable first - now based on EmpId)To show a list of events without names then you just look at the Eventstable.To show a list of events WITH names then you must create a query based onboth tables, including the name from the Employees table.Post back here with any issues arising.RegardsPeter Russell The name will be held in every record. You could hold an employeeid instead but it would mean modifying the Employees table to add an id field and then doing a couple of updates on the Events table to change to an id based field. Space doesn''t matter unless you have more than say, 100,000 employees on file. However it would be better to change the Events table to contain an id rather than a name. People''s names do change and an id field would enable the name to be changed and shown everywhere in the database. For the Employees table you need to add an Autonumber field as a primary key field. So you would have: EmpID Autonumber (PK) EmployeeName Text 50 To change the Events table you first need to create a temporary table tempEvents which contains both the EmployeeName and the Empid. Create a maketable query which uses both current tables, linked on EmployeeName. Add all fields from the Events table and the Empid field from the Employees table. Run this query and check some sample values from the table to make sure that the correct ID has been associated with each name. Rename the old events table as OldEvents. Rename tempEvents to Events. Delete the Employee name field from the new Events table. (You might have to delete and re-create relationships between the two table first - now based on EmpId) To show a list of events without names then you just look at the Events table. To show a list of events WITH names then you must create a query based on both tables, including the name from the Employees table. Post back here with any issues arising. Regards Peter Russell 这篇关于数据库大小优化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-05 17:06
查看更多