English 中文(简体)
• 如何维持KQ中可使用的项目订单
原标题:How to maintain user-modifiable order of items in SQL

我的申请处理的是包裹和文件之间的多对一的关系。 一揽子文件载有多项文件。 它们目前存放在邮政总局数据库,使用表 / Pack文件,表格<编码><>>>>。 外国关键栏目<代码>包装-id。

一项新要求要求用户能够重新安排一揽子文件中的文件顺序,因此,我需要开始跟踪。 请注意,此类命令不以文件的任何财产为依据,例如日期;该命令可由用户任意指定和重新签署。 我需要在各种选择中作出决定。 似乎并非难过的是:

  • Introduce a linking table, with columns package-id, document-id, sequence
  • Add a column to package to list the order (less change in structure, but now we have relationships pointing in both directions)
  • Am I missing a better solution?

这必须是一个共同的情景——制定这种方案的标准方式是什么?

问题回答

As discussed in the comments, only one sort is needed (e.g., the same sort applies to all users).

因此,最容易/最简单的解决办法是修改文件表。

  • It already has a link to package
  • You can also add a sequence or sort number there
  • This effectively says this document is in this package at this position

然而,还有多个有待决定的问题。

  • Does every document in a package need to have a position? (e.g., is the position column NOT NULL)?
    • If so, then you ll need to a) go back and update all documents with their positions, and b) modify any things for new documents , old documents and the like to also add the position numbers
    • If not, you need to have a clear rule for how to deal with documents without positions e.g., they automatically go to the end of this list. This may be an easier approach than requiring a position.
  • How to deal with positions no longer being in order e.g., if you have 4 ordered documents, and one is deleted (doc no longer needed), does it work ok with positions (say) 1, 2, 4? Or do you need to re-write them as 1, 2, 3?

最后,有些执行 我已做过,分类是一组数据的补充。 在这些情况下,我单独提交了一份表格(相当于一揽子补助、文件证明、顺序编号),以留下原始数据。 但是,这只是一种分治/主要的解决办法,而不是最简单的解决办法。 (从技术上说,我最简单地忽视和删除,因为别无他用这个新桌。)





相关问题
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 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签