tabel1中的相同ID,它是表2中具有相同ID的不同列的PK [英] Same ID from the tabel1 which is a PK to different columns with the same ID in table2

查看:90
本文介绍了tabel1中的相同ID,它是表2中具有相同ID的不同列的PK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个Windows窗体,这个窗体有一个

1.用户可以附加多个文件(任何类型的文件),这些附加的文件必须转到表A并且必须保存为Attachment1,attachments2, - (我们可以将不同扩展名的附件数量限制为5)分别针对相同的ID)

示例:如果表A中的ID为1234。我必须在不同的列中获取附件,例如

附件1 ID - 1234

附件2 ID -1234在不同栏中

这些文件必须显示在数据网格视图中

我能够以正确的方式获得一个文件,我甚至可以在数据网格视图中看到文件的内容。

问题:

我无法为辅助表中附加的所有文件获取相同的ID,因为主表ID列是唯一标识符。

II需要编写一个sql查询来获取具有相同ID的不同附件这样

附件1 ID - 1234

附件2 ID - 1234



预先谢谢



我尝试过:



我可以附加一个文件来查看,因为它在表1中没有重复值,但在附加多个文件时不起作用

There is a windows form and this form has an
1. where a user can attach multiple files (any type of file) and these files attached has to go to the Table A and have to be saved as Attachment1, attachments2,--(we can limit the number of attachments to 5 with different extensions) in different columns respectively for the same ID)
example: if ID from Table A is 1234. I have to get the attachments in different columns like the
Attachment 1 ID – 1234
Attachment 2 ID -1234 in different columns
And these files has to be displayed in the data grid view
I am able to get one file working the correct way as I wanted I can even see the content of the files in the data grid view.
Problem:
I am not able to get the same ID for all the files attached in the secondary table because the primary table ID column is a unique identifier.
II need to write a sql query to get the different attachments with same ID like this
Attachment 1 ID – 1234
Attachment 2 ID -1234

Thanks In advance

What I have tried:

I can get one file attached to be viewd since it has no duplicate values in table 1 but doesn't work when attached more than 1 file

推荐答案

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



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



附件(表)列 -

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.


这篇关于tabel1中的相同ID,它是表2中具有相同ID的不同列的PK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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