[英]Truncates Long Text/Memo string to 255 characters when it is a primary key field or “Indexed: Yes (no-duplicates) allowed”
I created a table in MS Access 2013 with only one column of "Long Text" type (called as Memo earlier) and made it the primary key of the table. 我在MS Access 2013中创建了一个表,其中只有一列“长文本”类型(之前称为Memo),并使其成为该表的主键。 I stored a long string of 255+ characters and then I tried to store another string whose first 255 characters were same as previous stored string but all other characters after first 255 were different and MS Access gave "duplicate data" error. 我存储了一个由255个以上的字符组成的长字符串,然后尝试存储另一个字符串,其前255个字符与先前存储的字符串相同,但是前255个字符之后的所有其他字符均不同,并且MS Access提供了“重复数据”错误。 In the new string I changed the characters that were after 255th position, using different combinations of characters and all gave error. 在新的字符串中,我使用不同的字符组合更改了位于第255位之后的字符,所有字符均出错。 But when I change any character before the 255th position it does not give any error. 但是,当我在第255位之前更改任何字符时,不会出现任何错误。 So, I concluded that MS Access checks only the first 255 characters of "Long Text" data type for checking duplicates in that column. 因此,我得出结论,MS Access仅检查“长文本”数据类型的前255个字符,以检查该列中的重复项。 Is it so? 是这样吗? What else could be reason? 还有什么可能是原因?
String Stored of 256 characters: LoremIpsumissimplydummytextoftheprintingandtypesettingindustryLoremIpsumhasbeentheindustrysstandarddummytexteversincethe1500swhenanunknownprintertookagalleyoftypeandscrambledittomakeatypespecimenbookIthassurvivednotonlyfivecenturiesbutalsotheleapintoelectr 存储的256个字符的字符串:LoremIpsumiss隐含印刷和类型设置行业的伪文本LoremIpsum自1500年代以来一直是工业标准的伪文本,当不明的印刷字体版本和加扰类型变为标本样本时,仍然可以存活五个世纪
String Gave Error: LoremIpsumissimplydummytextoftheprintingandtypesettingindustryLoremIpsumhasbeentheindustrysstandarddummytexteversincethe1500swhenanunknownprintertookagalleyoftypeandscrambledittomakeatypespecimenbookIthassurvivednotonlyfivecenturiesbutalsotheleapintoelect1 字符串给定错误:LoremIpsum暗示了印刷和类型设置行业的伪文本LoremIpsum自1500年代起就一直是行业标准的伪文本,当时未知的ertert agalley的类型和内容都乱七八糟,使它成为一种类型的样本书,只有五个世纪才得以生存,但是
String Gave Error: LoremIpsumissimplydummytextoftheprintingandtypesettingindustryLoremIpsumhasbeentheindustrysstandarddummytexteversincethe1500swhenanunknownprintertookagalleyoftypeandscrambledittomakeatypespecimenbookIthassurvivednotonlyfivecenturiesbutalsotheleapintoelect2 字符串给定错误:LoremIpsum暗示了印刷和类型设置行业的伪文本LoremIpsum自1500年代起就一直是行业标准的伪文本,当时未知的ertert agalley类型和加扰使它成为一种类型的样本书Ithassurvived不仅五个世纪而且还
String Gave Error: LoremIpsumissimplydummytextoftheprintingandtypesettingindustryLoremIpsumhasbeentheindustrysstandarddummytexteversincethe1500swhenanunknownprintertookagalleyoftypeandscrambledittomakeatypespecimenbookIthassurvivednotonlyfivecenturiesbutalsotheleapintoelect123 字符串给定错误:LoremIpsum暗示了印刷和类型设置行业的虚拟文本,LoremIpsum自1500年代起就一直是行业标准的虚拟文本,当时一种未知的印刷品种类繁多,并且乱七八糟地使它成为一种类型的标本,Isas幸存下来只有五个世纪,但是
Does Not Give Error: LoremIpsumissimplydummytextoftheprintingandtypesettingindustryLoremIpsumhasbeentheindustrysstandarddummytexteversincethe1500swhenanunknownprintertookagalleyoftypeandscrambledittomakeatypespecimenbookIthassurvivednotonlyfivecenturiesbutalsotheleapintoelec1 不给出错误:LoremIpsum暗示着印刷和版式设置行业的虚拟文本LoremIpsum自1500年代起就一直是行业标准的虚拟文本,当一种未知的印刷字体版本和拼写成一种类型的样本书时,它只能存活五个世纪,而且还保留了一个世纪。
Does Not Give Error: LoremIpsumissimplydummytextoftheprintingandtypesettingindustryLoremIpsumhasbeentheindustrysstandarddummytexteversincethe1500swhenanunknownprintertookagalleyoftypeandscrambledittomakeatypespecimenbookIthassurvivednotonlyfivecenturiesbutalsotheleapintoelec2 不给出错误:LoremIpsum暗示着印刷和版式设置行业的虚拟文本LoremIpsum自1500年代起就一直是行业标准的虚拟文本,当不明类型的印刷品和杂乱无章地拼写成一种标本样本Ithas存活下来时,也只有五个世纪了
Does Not Give Error: LoremIpsumissimplydummytextoftheprintingandtypesettingindustryLoremIpsumhasbeentheindustrysstandarddummytexteversincethe1500swhenanunknownprintertookagalleyoftypeandscrambledittomakeatypespecimenbookIthassurvivednotonlyfivecenturiesbutalsotheleapintoelec3 不给出错误:LoremIpsum暗示着印刷和类型设置行业的虚拟文本LoremIpsum自1500年代起就一直是行业标准的虚拟文本,当不明类型的印刷品库和类型样本乱七八糟时,它只能存活五个世纪,而且还保留了三个世纪。
Please notice the difference in the last few characters of above samples. 请注意上述示例的最后几个字符的区别。 The first stored string has 256 characters. 第一个存储的字符串包含256个字符。 Even if the column is not the primary key, the problem remains same if "Indexed: Yes (no-duplicates) allowed" value is set true in the table design for that column. 即使该列不是主键,如果在该列的表设计中将“索引:是(允许(无重复)允许”)值设置为true,问题仍然存在。
As @HansUp stated in the comments, Access (specifically the Jet/ACE db engine) only uses the first 255 characters of a Memo/Long Text field to create its index. 正如@HansUp在注释中所述,Access(特别是Jet / ACE数据库引擎)仅使用“备注/长文本”字段的前255个字符来创建其索引。 Hence, it only uses the first 255 characters to enforce No Duplicates. 因此,它仅使用前255个字符来强制执行“无重复”。
@HansUp's advice to use a different db engine that provides better support for long strings and Full Text search is probably the best approach, but I understand there are often other considerations that may be limiting you to solving your problem in Access. @HansUp建议使用不同的数据库引擎为长字符串提供更好的支持,而全文本搜索可能是最好的方法,但是我知道通常还有其他一些考虑因素可能会限制您解决Access中的问题。
As such, here is an Access-only approach to solving your problem. 因此,这是解决问题的“仅访问”方法。 This assumes the requirement you listed in the comments is valid; 假设您在注释中列出的要求是有效的; ie, you need to store unique strings of between 400 and 1000 characters. 即,您需要存储400到1000个字符的唯一字符串。
Alternative 1 选择1
Alternative 2: 选择2:
Keep your current setup and enforce the uniqueness at code level. 保持当前设置,并在代码级别实施唯一性。 Every time you update or insert a note, do a search on all notes that match the first 255 characters, read the value and perform the comparison in code. 每次更新或插入注释时,都对与前255个字符匹配的所有注释进行搜索,读取值并执行代码比较。
Alternative 3 ( thanks to @HansUp for suggesting this in the comments ): 备选方案3( 感谢@HansUp在评论中建议 ):
Notes for this method : 此方法的注意事项 :
And yes, I still highly recommend @HansUp's solution to simply use a different db engine. 是的,我仍然强烈建议@HansUp的解决方案仅使用其他数据库引擎。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.