Avatar billede bojohansen Nybegynder
27. februar 2004 - 17:11 Der er 11 kommentarer og
1 løsning

Relationer og måden at gemme data på, hastighed.

Jeg vil til at granulere mine databaser noget mere og bruge relationer, har læst en del på det men har lige et par spørgsmål.

1)
Det at man trækker linier imellem feldterne i sin db i access's relations vindue, har det nogen betydning udover at man selv senere kan sidde og se hvad man egentligt hat tænkt sig da man lavede databasen?
Man skal jo definere sine forespørgelser i SQL'en alligevel?

2)
Hvis nu man har en db som indeholder 2 tables

Table-1
Navn
Adresse
etc.etc.
HusDyr

Table-2
HusDyrID
HusDyr

En person har 15 husdyr.
Lægger man HusDyrID fra Table-2 ind i HusDyr i table-1 sepereret med komma : 12,35,456,278,etc. etc.
eller hvad gør man smartest for at spare plads og øge hastigheden i databasen.
Der skal hovedsagelig vises data og ikke så ofte indsættes data.
Det skal bruges online på .asp
Avatar billede bojohansen Nybegynder
27. februar 2004 - 17:44 #1
Ville man oprette et table-3

PersonID (Fra table-1)
HusdyrID (Fra table-2)
Der er nu 15 rekker med PersonID=1 som indeholder hver sin værdi af HusDyrID

PersonID=1  HusDyrID=12
PersonID=1  HusDyrID=35
PersonID=1  HusDyrID=456
PersonID=1  HusDyrID=278
PersonID=1  HusDyrID=etc.etc
Avatar billede bojohansen Nybegynder
27. februar 2004 - 17:45 #2
Jeg syntes bare at Table-3 kunne gå hen og blive forfærdelig stor, og langsom hvis alle brugere har 15 eller flere HusDyr
Avatar billede terry Ekspert
27. februar 2004 - 18:03 #3
Table-1
HusNrID
Navn
Adresse
etc.etc.




Table-2
HusDyrID
HusDyr


Table-3
HusNrID
HusDyrID
Avatar billede terry Ekspert
27. februar 2004 - 18:08 #4
A person(house or what ever) can have one or more pets (cat, dog, rabbbit etc.)

and a pet can be owned by on eor more persons. So you have what is called a many-to-many relationship. And as is always the case in this type of relationship you need THREE tables. The third table contains links between the other two. An example:

Table-1
HusNrID Navn
1    "Peter Pan"
2    "bojohansen"

Table-2
HusDyrID HusDyr
1        "Cat"
2        "Dog"
3        "Rabbit"

Table-3
HusNrID HusDyrID
1      1
1      2
2      3

From this we can see that Peter Pan has a cat and a dog, and  you have a rabbit :o)
Avatar billede terry Ekspert
27. februar 2004 - 18:10 #5
In table 2 you could also have a field for teh name of the pet and other information specif only to that pet (age, colour etc)
Avatar billede bojohansen Nybegynder
27. februar 2004 - 18:40 #6
Thanks Terry, then this would be the correct and fastes way to do it.

Do you have a comment on question 1?

1)
Does it have any effect on the database that one draw the lines between tables and fields in the Relationship window, defining the relationship One to Many - Many to Many and so on? Or is it just to help the developer with a visual guide to what he is doing and thinking when building the database.
I mean, you have to define your queryes any way, its not like you just SQL your main table and all relations to this automatically follows with it.
Select * from Table-1 Where HusNrId = '1'
Wouldent give me any data from other tables bound to Table-1 HusNrId 1 anyway
Avatar billede terry Ekspert
27. februar 2004 - 19:02 #7
By using the relationships window you can also alter the realationship type and also the referential integrity. Right click on the thin line and you will see what I mean. But here is NO NEED to use this!
If you use it and make a query then the relationships will get added automatically!
Avatar billede bojohansen Nybegynder
27. februar 2004 - 19:43 #8
Ok, thanks Terry.

Do you have a link to some site really digging deep into the borders of Normalisation, De-Normalisation where to set the limit to keep the speed up on your databases.
The queryes can get pretty complicated and heavy on the database if i Normalise to much.
Avatar billede terry Ekspert
28. februar 2004 - 09:31 #9
What will help is to make sure that fields you use often in your WHERE criteria are indexed.
I dont have any links concerning limits in Normalisation I have one which may be usefull. and You will be able to find many on th eweb too.

http://www.hedeskov.dk/netpublikationer/udv-database/kap3/kapitel3.htm
Avatar billede bojohansen Nybegynder
28. februar 2004 - 11:23 #10
I have searched the net for info on it, already read all of the chapters on hedeskov.dk, but i cant seem to find any conclusion, explanation or guide saying that "exceeding 5 or more tables in a search criterea will make your db slow".
Well i can see that such a guide is very difficult to make as it dependts on many factors on each and every db.
Thanks again Terry, your info was a great help :-)
Avatar billede terry Ekspert
28. februar 2004 - 12:31 #11
where have you seen that joining five tables will slow the dB? It depends on many factor. As mentioned previosuly make sure your WHERE criteia fields which you often use are indexed, and only select the fields you need NOT SELECT * (ALL)!
Avatar billede bojohansen Nybegynder
28. februar 2004 - 12:57 #12
I have read it a lot of different places, and it seems logical to me.
For each table that you include in a query, the db wil have to run through that table, so running through 1 table instead of 5, would sound more fast.
Offcourse have data from 5 tables stored in one would make the table quite big, and hold a lot of data more than once (Redundance I think its called), and make search time big.........
I also read some where (A loong time ago) that selecting * instead of defining the fields would speed the queryes up, something about access not needing to sort the data or something like that.
Havent really used the * anyway, cause it seems unlogically that it would be faster.
I would presume that using the * would just fill your RAM and use more system resurces.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester