English 中文(简体)
3. 处理个人病和全球性疾病
原标题:handling of indvidual id and global id

I have an app that uses standard id integer autoincrement values. I also have another table that manages a global_id which is currently set as an integer. I m thinking it would be preferable to use a non-integer for this global value so that it would be clear whether the item id or global id is being used based upon existence of a non-integer: for example:

site.com/item/id/123 - item id
site.com/item/id/12j45 - global id

在内部,全球身份查验表仍将保持其贴现价值(而不是确保这一点)。 但是,我很想得到一个无动于衷的全球——身份认同者。 是否有可以处理这一问题的MySQL数据类型? 同样的,一次性(潜在)随机性(1至1b、2至2d)。

是否有更好的办法处理这一问题? 例如,在考虑将所涉物体与已登记的物体相提并论——因此,地点为123,但成为全球价值123。 也许有铁路部分已经这样做?

th

@Doug
yes regarding uniqueness across tables; basically, a version of the object relational impedence mismatch issue (lists of objects). There is currently two sets of ids and I manage it manually similar to what you propose as two namespaces.

The namespaces are not needed though because if one is set up as int only and the other is set up as anything else, you know you are looking at a global_id.

最佳回答

最好有两个名称空间,例如:

site.com/item/id/123
site.com/item/gid/12j45

Otherwise, you would be requiring the global_id to have a character to differentiate it from the integer field, and create unnecessary cycles to determine how to query the data, based on the content of the data.

你们试图以全球名义来完成什么? 它是多个表格的独特程度吗? 如果是的话,仅仅向id方发出一封信就够了。 也许会建立几个触发点,但我想通过这一进程再说几句。

最新资料:对于多个表格的独一无二之处,答案是一成不变的:

CREATE TABLE global_references (
    id int NOT NULL auto_increment PRIMARY KEY,
    reference_type varchar(50) NOT NULL,
    reference_id int NOT NULL,
    UNIQUE KEY akGlobalReferences (reference_type, reference_id);

当你增加新的记录时,在本表中插入一个与表格名称和新的背书相对的行文,并将由此产生的id作为你的全球独特国际发展法。

你们可能已经这样做,并且正在寻找另一种储存方法来补充特性。 如果你真的想要获得两种类型的身份证,我只建议对国际发展法领域作出推定。 例如,如果两个核心部分:

sites.com/item/id/123
sites.com/item/id/g123

您将检查第一个特点。 如果有<代码>g,则将其从全球表中删除并核对。 否则,检查有关表格。 然而,我仍建议为此单独拨款。

问题回答

I would just use a varchar for this field. That way, you can append whatever you want to the original item id. Maybe add something like _a27d to the original id (underscore plus 4 random characters) -- so you can always look before the underscore and get your original id back.

你们可以避免获得当地补贴和全球补贴。

CREATE TABLE global_ids (
    id int NOT NULL auto_increment PRIMARY KEY);

Each of the tables has its own id that has a foreign key to the global_ids table.

CREATE TABLE t1 (
    id int NOT NULL auto_increment PRIMARY KEY,
    FOREIGN KEY (id) REFERENCES global_ids(id));

CREATE TABLE t2 (
    id int NOT NULL auto_increment PRIMARY KEY,
    FOREIGN KEY (id) REFERENCES global_ids(id));

你们最后还有两个字句(一个是全球女,一个是实际表格),但你不需要处理两种类型的补贴。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签