Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 12-18-2003, 10:19 AM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,490
sde is on a distinguished road
Keys vs Indexes

When working with databases, what exactly is the difference between a key and index?

It seems like when you set a key, it indexes by that key, but is there something else?
__________________
Mike
sde is offline   Reply With Quote
Old 12-19-2003, 10:52 AM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,490
sde is on a distinguished road
well , here is what i found: when you make a field a 'primary key' , that field is 'unique' and indexed by that field. when you index a field, it does not have to be unique, but will index by that field.
__________________
Mike
sde is offline   Reply With Quote
Old 02-03-2004, 09:07 AM   #3 (permalink)
Sir R4T IV
Registered User
 
Join Date: Feb 2004
Posts: 6
Sir R4T IV is on a distinguished road
right now, i'm just starting my dbms course in my college. i could pretty well do the assignment i was given, to index some tabbles on smoe specific columns, and so on...

forgive me for being a newbie, but what i don't understand is what is all this indexing for? what does index really mean? and what are foreign keys? another thing i didn't understand is referencing in tables. what does referencing another table mean? hope you don't get angry at my ignorance!
Sir R4T IV is offline   Reply With Quote
Old 02-03-2004, 09:50 AM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,490
sde is on a distinguished road
we don't get angry for n00bs here, this is code newbie =)

indexing is sorta like alphabetizing your records by the field you most likely will be searching for. i didn't understand it very well until i started working with db2. i can't use SQL to read a db2 file ( with rpg on an as/400 ), so i have to read it almost like a text file.

for example, i have a contact table keyed by last name. these 3 records would reside in the database in this order:
Code:
sharon dough
joe duran
peter smith
if they were indexed by first name, it would be:
Code:
joe duran
peter smith
sharon dough
your SQL searches would work no matter what, but if you were searching by last name and a file keyed by last name, your results would return much faster.
__________________
Mike
sde is offline   Reply With Quote
Old 02-04-2004, 11:10 PM   #5 (permalink)
Sir R4T IV
Registered User
 
Join Date: Feb 2004
Posts: 6
Sir R4T IV is on a distinguished road
So it means the entries in the database are already in order?
suppose i was to enter values in this seq:

sharon dough
joe duran
peter smith
dorothy jones

would the query
Code:
select * from names
result in

sharon dough
joe duran
peter smith
dorothy jones

? or in

sharon dough
joe duran
dorothy jones
peter smith
Sir R4T IV is offline   Reply With Quote
Old 02-05-2004, 07:44 AM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,490
sde is on a distinguished road
yes, i'm pretty sure in most databases, it will be in order of the index unless you specify an 'ORDER BY' clause in the query.
__________________
Mike
sde is offline   Reply With Quote
Old 02-06-2004, 08:01 PM   #7 (permalink)
Sir R4T IV
Registered User
 
Join Date: Feb 2004
Posts: 6
Sir R4T IV is on a distinguished road
Hey thanks a lot.
Sir R4T IV is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
capturing multiple keys sde MS Technologies ( ASP, VB, C#, .NET ) 0 01-20-2004 02:17 PM


All times are GMT -8. The time now is 04:36 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting