且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

tabel1中的相同ID,它是表2中具有相同ID的不同列的PK

更新时间:2022-12-12 09:01:32

如果你发布表格模式,它将有助于找出你想要的东西。



现在听起来像你有包含这样的列的模式:



附件(表)列 -

TableAID

附件1

附件2

附件3

附件4

附件5



如果你的表格结构如下,那么你可以选择TableAID = 1234.



但我要做的是重新组织你的标签le并删除Attachment *列并存储为单独的行。这样的事情:



附件(表格)栏目 -

附件ID

TableAID(fk到TableA)

附件



这种方式可以存储5个以上的文件,但也可以根据TableA ID获取所有文件。
If you post you table schema it would help figure out what you are trying to.

Right now is sounds like you have a schema with columns like this:

Attachments (table) columns -
TableAID
Attachment1
Attachment2
Attachment3
Attachment4
Attachment5

If you table is structured like this then you can just select on the TableAID = 1234.

But what I would do is reorganize your table and remove the Attachment* columns and store as individual rows. Something like this:

Attachments (table) columns -
AttachmentID
TableAID (fk to TableA)
Attachment

This way you can store more than 5 files but also get all files based on the TableA ID.


这些表应该构造为父/子关系。换句话说,你应该有一个父表,比如Table1,它包含附件的公共属性。例如

The tables should be structured as parent/child relations. In other words you should have a parent table, say Table1 which contains common attributes for attachments. For example
Table1
----------
- Table1Key, primary key, auto-generated
- UploadInfo, for example session info about upload
- etc...



既然你想要实际的附件共享一个共同的密钥,那么你会有表1的外键引用。因此,如果表2包含附件,则结构可能类似于


Now since you wanted the actual attachments to share a common key, then you would have a foreign key reference to Table1. So if Table 2 contains the attachments then the structure could be like

Table2
-----------
- Table2Key, primary key, auto-generated
- Table1Key, foreign key, points to Table1
- AttachmentName, file name
- etc





所以数据可能就像



表1



So the data could be like

Table1

Table1Key SessionInfo
--------- ------------
1         Session2, user x
2         Session214, user y
3         Session7, user z



表2


Table2

Table2Key Table1Key AttachmentName
--------- --------- --------------
1         1         FileABC
2         1         FileTRE
3         1         File546
4         2         File495
5         3         FileKLI
6         3         FileSRG
7         3         FileUIU
8         3         FileUIG
9         3         FileCDF



有了这种s结构很容易处理不同数量的附件及其与父表的关系。


With this kind of structure it's easy for you to handle different amounts of attachments and their relations to parent table.