我如何在表之间建立这种关系 [英] How I can do this relation between tables

查看:66
本文介绍了我如何在表之间建立这种关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在桌子上访问



表不,1内容

i have to table in access

table No,1 Content

Names , Students grade
qassem . 300
noor    . 280





表不,2个内容





table No,2 content

schoolsName , Students grade
aaaaaaa   .   290
bbbbbbb    . 270
ccccccc    . 250





i希望在C#2012视觉工作室中将这些表格链接到我们



当学生的最终成绩打开所有学校时



之后,每个学生按照给他的成绩打开他的选择



我无法链接到他们

谢谢

i am Egyptian

我的一些英语知识



i want to link those table with us in C# 2012 visual studio

When the students' final grades open them all schools

After that each student opens his choices by grade given to him

I can not link to them
thank you
i am Egyptian
A few my knowledge in English

推荐答案

您需要主表中的主键和详细信息表中的外键,然后从SQL Server管理工作室中为此2个键和VB .Net进行连接你使用2个bindingsource对象进行相同的连接。
You need a primary key in the master table and a Foreign key in the detail table, then from SQL Server managment studio you do the join for this 2 keys and in VB .Net you do the same same join with 2 bindingsource objects.


问题是为了在表之间建立关系,它们需要有一个共同的值。它就像一个MP3:它有一个标题,但它也有一个音乐家(或乐队)制作它。所以你可以有两张桌子:

艺术家:

The problem is that in order to establish a relationship between tables, they need to have a common value. It's like an MP3: it has a title, but it also has a musician (or band) that made it. So you could have two tables:
Artists:
ID    ArtistName
1     Lana Del Ray
2     Coldplay
...

因为一个乐队或艺术家可能会产生多个曲目,所以将它们存储在自己的表中是有意义的 - 否则你将复制一个乐队名称,并且再一次。

和一张曲目表:

曲目:

Because a band or artist is likely to produce more than one track, it makes sense to store them in their own table - otherwise you will be duplicating teh smae band name over, and over again.
And a Tracks table:
Tracks:

ID    ArtistID   TrackName
1     1          Gods and Monsters
2     1          Ride
3     2          Paradise
4     2          Fix You
...



你可以在Tracks.ArtistID和Artists.ID列上的曲目和艺术家之间建立外键关系。

这可以让你获取相关信息:


And you can establish a foreign key relationship between the Tracks and Artists on the Tracks.ArtistID and Artists.ID columns.
That lets you fetch related information:

SELECT a.ArtistName, t.TrackName
FROM Tracks t
JOIN Artists a ON t.ArtistID=a.ID

然后返回:

And that returns you:

Gods and Monsters  Lana Del Ray
Ride               Lana Del Ray
Paradise           Coldplay
Fix You            Coldplay
...

但如果你没有连结专栏 ArtistsID然后没有办法连接两张桌子。



但是......在你的例子中,你不想要链接根本没有。

您要做的是检查每个学生成绩与学校将接受的最低价值,并显示学生可以去哪些学校。

那是只是一个简单的SQL查询:

But if you don't have the "linking column" of the ArtistsID then there isn't a way to "connect" the two tables.

But...in your example, you don't want a "link" at all.
What you want to do is check each student grade against the minimum value the schools will accept and show which schools the student can go to.
That's just a simple SQL query:

SELECT Students.StudentName, Schools.SchoolName FROM Students, Schools
WHERE Students.Grade >= Schools.MinGrade

这给出了你:

And that gives you:

StudentName	SchoolName
qassem	    aaaaaaa
qassem	    bbbbbbb
qassem	    ccccccc
noor	    bbbbbbb
noor	    ccccccc


这篇关于我如何在表之间建立这种关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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