MySQL:MySQL表中的每条记录都有类似内部记录的标识符吗? [英] MySQL: is there something like an internal record identifier for every record in a MySQL table?

查看:131
本文介绍了MySQL:MySQL表中的每条记录都有类似内部记录的标识符吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MySQL作为存储来构建电子表格应用程序,我需要标识正在客户端更新的记录以保存更改.

I'm building a spreadsheet app using MySQL as storage, I need to identify records that are being updated client-side in order to save the changes.

有没有一种方法,例如某种内部记录标识符"(数据库引擎本身使用的内部记录标识符)来唯一地标识记录,以便我能够更新正确的记录?

Is there a way, such as some kind of "internal record identifier" (internal as in used by the database engine itself), to uniquely identify records, so that I'll be able to update the correct one?

当然,可以使用SELECT查询来标识记录,包括表中的所有字段,但是显然,在大多数情况下,这样做的缺点是返回多个记录.

Certainly, a SELECT query can be used to identify the record, including all the fields in the table, but obviously that has the downside of returning multiple records in most situations.

重要提示:电子表格应用程序旨在在任何表上工作,甚至是设计非常糟糕的表,也没有任何键,因此,诸如使用UNIQUE索引定义字段并使用该字段"之类的解决方案是不可行的,表结构可能变数很大,没关系.

IMPORTANT: the spreadsheet app aims to work on ANY table, even ones tremendously poorly designed, without any keys, so solutions such as "define a field with an UNIQUE index and work with that" are not an option, table structure may be extremely variable and must not matter.

非常感谢.

推荐答案

AFAIK不存在这样的唯一内部标识符(例如,简单的行ID).

AFAIK no such unique internal identifier (say, a simple row ID) exists.

可能 也许可以无需任何排序即可运行SELECT,然后使用LIMIT获得第n行.在可靠可靠的条件下,需要确认mySQL Guru.可能永远不会.

You may maybe be able to run a SELECT without any sorting and then get the n-th row using a LIMIT. Under what conditions that is reliable and safe to use, a mySQL Guru would need to confirm. It probably never is.

尝试使用 phpMyAdmin ,它是mySQL的Web前端.它被设计用来处理没有键的设计不良的表.如果我没记错的话,它会使用 all 列,在这种情况下可以保留它们:

Try playing around with phpMyAdmin, the web frontend to mySQL. It is designed to deal with badly designed tables without keys. If I remember correctly, it uses all columns it can get hold of in such cases:

UPDATE xyz set a = b WHERE 'fieldname'  = 'value' 
                       AND 'fieldname2' = 'value2' 
                       AND 'fieldname3' = 'value3' 
                       LIMIT 0,1;

,依此类推.

当然,这也不完全是重复安全的.

That isn't entirely duplicate-safe either, of course.

我想到的唯一想法是在运行时添加键列,并在应用程序完成后将其删除.这是诱发鸡皮b的想法,但总比没有好.

The only idea that comes to my mind is to add a key column at runtime, and to remove it when your app is done. It's a goose-bump-inducing idea, but maybe better than nothing.

这篇关于MySQL:MySQL表中的每条记录都有类似内部记录的标识符吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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