b3ta.com qotw
You are not logged in. Login or Signup
Home » Question of the Week » Off Topic » Post 1608031 | Search
This is a question Off Topic

Are you a QOTWer? Do you want to start a thread that isn't a direct answer to the current QOTW? Then this place, gentle poster, is your friend.

(, Sun 1 Apr 2001, 1:00)
Pages: Latest, 836, 835, 834, 833, 832, ... 1

« Go Back | See The Full Thread

No worries, I can explain this which will teach you a few things.
Do you know the idea behind Primary Keys and Secondary Keys?
(, Fri 4 May 2012, 21:12, 1 reply, 12 years ago)
Um.... no?

(, Fri 4 May 2012, 21:13, Reply)
How about a spreadsheet?

(, Fri 4 May 2012, 21:15, Reply)
That one I do know.

(, Fri 4 May 2012, 21:15, Reply)
Cool, OK.
A database is a series of spreadsheets called 'tables'. For the sake of simplicity, you give each column a name and type (such as if you're expecting a number or some words or lots of words). Then each row is one line of data.

In order to know you're looking at the right row, you have something called a Primary Key. This is normally a number that goes from 1 to a zillion, but sometimes its a bunch of random characters known as a 'hash', or if you _know_ you can put some words in that'll be unique for that line, you can use that. The best way is to use numbers that autoamticly go up by 1, because you can judge how it works better.

Then sometimes you might want what they call a Secondary Key, this is one of the other (or same)'s primary keys, so you can make a 'join' between the two rows.

There are differnt types of joins, but I'll start at the front. "One to many" where one row can have many rows using it's secondary key.

So say you have a table of CUSTOMERS with the columns "UserID" (the Pimary Key), "Name" and "address". "One customer can have (to) Many orders". You could have a second table with ORDERS on it. So that could have "OrderID", "CustomerID" and "Product Name".... the Customer ID (secondary key) would be = to someone's UserID (primary key) on the other table.


....... does this make sense?
(, Fri 4 May 2012, 21:27, Reply)
...
Customer Table
|UserID|Name|Adddress|
|1 | B3th | Bristol
|2 | Gonz | London
|3 | Barry | HMPS Holloway.

Order Table
|OrderID| CustomerID | Product|
| 1 | 1 | Shirts |
| 2 | 1 | Shorts |
| 3 | 2 | Condoms |
| 4 | 3 | Sunglasses |
|5 | 1 | train ticket to london.

---------------------
So with this, we can see that b3th (userID: 1) bought Shirts, Shorts and a train ticket. That I bought condoms and barry bought some sunglasses.


//edit// My mistake, I placed myself in bristol, that I've now changed to london.
(, Fri 4 May 2012, 21:44, Reply)
Haha this is excellent

(, Fri 4 May 2012, 21:47, Reply)
I have learnt so much from these few posts

(, Fri 4 May 2012, 21:50, Reply)
=D
So using this, how would you two do the sheep thing I started this on?
(, Fri 4 May 2012, 21:55, Reply)
Really slowly.

(, Fri 4 May 2012, 22:01, Reply)
hmm
OK I would use a sheep ID as the primary key.
[sheepID],[name],[gender],[colour],[Generation],[kids]
using generation as the secondary key

as in
[generation],[sheepID],[name],[kids],{sheepID]*

*lists sheepID of ofspring
(, Fri 4 May 2012, 22:05, Reply)
Swot

(, Fri 4 May 2012, 22:06, Reply)
Is that correct?
Its probably too convoluted
(, Fri 4 May 2012, 22:07, Reply)
Dunno
I'm not trying to work it out.
I'm drinking and listening to music.
(, Fri 4 May 2012, 22:11, Reply)
woah me too
must be friday
(, Fri 4 May 2012, 22:22, Reply)
Almost, really close. You got the trick question in there... doing it all in one table.
But the one you would use

SheepID| Name* | *Colour | MotherID | FatherID |

Every sheep has a mother and father, but not all have children. You wouldn't use the offspring one because although you can have blank, not all of them would have kids. The FatherID and MotherID are the Secondary Keys and SheepID is the pimary key.

* not really relivent for this example, but its just to show that there are tables that _aren't_ keys.
(, Fri 4 May 2012, 22:12, Reply)
ah,
I assumed that I would need to keep track of the generations
(, Fri 4 May 2012, 22:13, Reply)
You can do that with this, see down there a bit =)

(, Fri 4 May 2012, 22:33, Reply)

Gonz, can you see the matrix?
(, Fri 4 May 2012, 22:16, Reply)
Haha, right click on most web pages and go 'view source'.
I can read all that like english, and pretty much like 99% of the stuff that its linked too.... and pretty much the level behind that which generates what you see. And the level behind that which is the database itself. That's where I'm fluent. The level behind that, which is the server stuff, I can semi-read (for lack of a better expression) but not enough to say its part of my job. The next layer behind that, the operating system, I can read, and the final layer which is the hardware, I don't have a clue.

It's more Inception than Matrix =)
(, Fri 4 May 2012, 22:35, Reply)
nice

(, Fri 4 May 2012, 22:43, Reply)
I think that would probably make sense
if my brain hadn't given up for the weekend.
(, Fri 4 May 2012, 22:22, Reply)
Hah, no worries, if you want any help or advice, I can give it.
I found a wicked programing learning tool last week which is what I'd be learning if I was starting out and not already good at what I do.
(, Fri 4 May 2012, 22:36, Reply)
ooh. hit me up.

(, Fri 4 May 2012, 22:42, Reply)

+side the head.
(, Fri 4 May 2012, 22:42, Reply)
Check this.
tryruby.org/levels/1/challenges/0
(, Fri 4 May 2012, 23:05, Reply)
I would learn HTML5 and CSS3 first though.

(, Fri 4 May 2012, 23:06, Reply)

« Go Back | See The Full Thread

Pages: Latest, 836, 835, 834, 833, 832, ... 1