473,416 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

proper format for this database table

Hi guys. I was wondering if someone could suggest some possible
structures for an "Education" table in a database. It will contain at
minimum university names, years of attendance, and degrees earned. My
problem is that I don't know quite how to set this up for people who
have attended multiple universities. I could do:

university text DEFAULT NULL,
yearStart integer DEFAULT NULL,
yearEnd integer DEFAULT NULL,
degreesEarned text DEFAULT NULL

But this only allows for one university. (Also not sure if I should
split up the years like that.) But mainly I'm looking for a way to
construct this table so it can hold multiple universities, if necessary.

Thanks.
Oct 19 '06 #1
14 1264
At Thursday 19/10/2006 17:07, John Salerno wrote:
>Hi guys. I was wondering if someone could suggest some possible
structures for an "Education" table in a database. It will contain at
minimum university names, years of attendance, and degrees earned. My
problem is that I don't know quite how to set this up for people who
have attended multiple universities. I could do:

university text DEFAULT NULL,
yearStart integer DEFAULT NULL,
yearEnd integer DEFAULT NULL,
degreesEarned text DEFAULT NULL

But this only allows for one university. (Also not sure if I should
split up the years like that.) But mainly I'm looking for a way to
construct this table so it can hold multiple universities, if necessary.
The relationship should be 1:n between a Person and its Education records.
Person 1<--->n Education
so just add a PersonId to the table and you're done.
Depending on your needs, later university and degreesEarned may
become entities instead of simple text attributes.
--
Gabriel Genellina
Softlab SRL

__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

Oct 19 '06 #2
John Salerno a écrit :
Hi guys. I was wondering if someone could suggest some possible
structures for an "Education" table in a database.
Wrong newsgroup, then. comp.database.* is right next door...

Oct 19 '06 #3

Gabriel Genellina wrote:
At Thursday 19/10/2006 17:07, John Salerno wrote:
Hi guys. I was wondering if someone could suggest some possible
structures for an "Education" table in a database. It will contain at
minimum university names, years of attendance, and degrees earned. My
problem is that I don't know quite how to set this up for people who
have attended multiple universities. I could do:

university text DEFAULT NULL,
yearStart integer DEFAULT NULL,
yearEnd integer DEFAULT NULL,
degreesEarned text DEFAULT NULL

But this only allows for one university. (Also not sure if I should
split up the years like that.) But mainly I'm looking for a way to
construct this table so it can hold multiple universities, if necessary.

The relationship should be 1:n between a Person and its Education records.
Person 1<--->n Education
so just add a PersonId to the table and you're done.
Depending on your needs, later university and degreesEarned may
become entities instead of simple text attributes.
And if multiple degrees are earned at the same university,
they should be in seperate records. So if you were thinking

[id] [university] [yearStart] [yearEnd] [degreesEarned]
1 U of I 1971 1977 BS MS PhD

you should rethink it as

[id] [university] [yearStart] [yearEnd] [degreeEarned]
1 U of I 1971 1975 BS
1 U of I 1975 1976 MS
1 U of I 1976 1977 PhD

Oct 19 '06 #4
John Salerno wrote:
Hi guys. I was wondering if someone could suggest some possible
structures for an "Education" table in a database. It will contain at
minimum university names, years of attendance, and degrees earned. My
problem is that I don't know quite how to set this up for people who
have attended multiple universities. I could do:

university text DEFAULT NULL,
yearStart integer DEFAULT NULL,
yearEnd integer DEFAULT NULL,
degreesEarned text DEFAULT NULL

But this only allows for one university. (Also not sure if I should
split up the years like that.) But mainly I'm looking for a way to
construct this table so it can hold multiple universities, if necessary.

Thanks.
Use associative tables.
Something like:

Table Students:
PK id (some unique id, maybe a student id#, or just an auto-inc)
name, etc...

Table Students2Education:
studentID (id from Students)
EducationID (id from Education)

Table Education:
id (probably just some auto-inc)
university
yearStart
yearEnd
degreesEarned

This way, if you have some students:

Students:
001 Jordan
and Jordan started university in 2003 @ Wentworth Institute of Technology:

Students2Education:
001 Wentworth_Institute_Of_Technology

Education:
1 Wentworth_Institute_Of_Technology 2003 NULL NULL

And then, in the future, say I go to MIT. By then I'll (hopefully) have
my CS degree...

Students:
001 Jordan

Students2Education:
001 Wentworth_Institute_Of_Technology

Education:
1 Wentworth_Institute_Of_Technology 2003 2007 BCOS
2 Massachusetts_Institute_Of_Technology 2008 NULL NULL

And I could go back to Wentworth and major in Computer Engineering this
time:

Education:
1 Wentworth_Institute_Of_Technology 2003 2007 BCOS
2 Wentworth_Institute_Of_Technology 2007 200

(You should probably use an integer ID for universities, and have a
separate table to link those to names. Something like:

Education:
UniversityID
yearStart
yearEnd
degreeEarned

Universities:
UniversityID
Name
City
Etc,etc)

In general, when you're having trouble representing something in a
database, it helps to break it down and model the smaller relationships
first, and use those as building blocks to model the whole relationship.

HTH.
Jordan Greenberg


--
Posted via a free Usenet account from http://www.teranews.com

Oct 19 '06 #5
me********@aol.com wrote:
you should rethink it as

[id] [university] [yearStart] [yearEnd] [degreeEarned]
1 U of I 1971 1975 BS
1 U of I 1975 1976 MS
1 U of I 1976 1977 PhD
Thanks guys. I do plan to have an id entry for each person as well, I
just forgot to mention that. But since it's a primary key, I didn't know
I could list it more than once. Or does primary key not necessarily mean
unique?
Oct 20 '06 #6
Bruno Desthuilliers wrote:
John Salerno a écrit :
>Hi guys. I was wondering if someone could suggest some possible
structures for an "Education" table in a database.

Wrong newsgroup, then. comp.database.* is right next door...
I know, I'm sorry. It's just that this newsgroup server doesn't have any
database ngs on it. :(
Oct 20 '06 #7
On Fri, 2006-10-20 at 10:57, John Salerno wrote:
me********@aol.com wrote:
you should rethink it as

[id] [university] [yearStart] [yearEnd] [degreeEarned]
1 U of I 1971 1975 BS
1 U of I 1975 1976 MS
1 U of I 1976 1977 PhD

Thanks guys. I do plan to have an id entry for each person as well, I
just forgot to mention that. But since it's a primary key, I didn't know
I could list it more than once. Or does primary key not necessarily mean
unique?
Primary key *does* mean unique in the table that defines it. However, if
you take a primary key ID from one table and store it in a different
table, that's a foreign key. There are no inherent uniqueness
constraints on a foreign key.

-Carsten
Oct 20 '06 #8
On 2006-10-20, John Salerno <jo******@NOSPAMgmail.comwrote:
Bruno Desthuilliers wrote:
>John Salerno a écrit :
>>Hi guys. I was wondering if someone could suggest some possible
structures for an "Education" table in a database.

Wrong newsgroup, then. comp.database.* is right next door...

I know, I'm sorry. It's just that this newsgroup server doesn't
have any database ngs on it. :(
Try Google Groups for these annoying cases.

--
Neil Cerutti
The audience is asked to remain seated until the end of the recession.
--Church Bulletin Blooper
Oct 20 '06 #9
Carsten Haese wrote:
>>[id] [university] [yearStart] [yearEnd] [degreeEarned]
1 U of I 1971 1975 BS
1 U of I 1975 1976 MS
1 U of I 1976 1977 PhD
Thanks guys. I do plan to have an id entry for each person as well, I
just forgot to mention that. But since it's a primary key, I didn't know
I could list it more than once. Or does primary key not necessarily mean
unique?

Primary key *does* mean unique in the table that defines it. However, if
you take a primary key ID from one table and store it in a different
table, that's a foreign key. There are no inherent uniqueness
constraints on a foreign key.
So in the example above, isn't that using the same primary key multiple
times in the same table?
Oct 20 '06 #10
Neil Cerutti wrote:
On 2006-10-20, John Salerno <jo******@NOSPAMgmail.comwrote:
>Bruno Desthuilliers wrote:
>>John Salerno a écrit :
Hi guys. I was wondering if someone could suggest some possible
structures for an "Education" table in a database.
Wrong newsgroup, then. comp.database.* is right next door...
I know, I'm sorry. It's just that this newsgroup server doesn't
have any database ngs on it. :(

Try Google Groups for these annoying cases.
True, didn't think of that. (Probably a good idea to make up a fake
account though, since GG posts your email address.)
Oct 20 '06 #11

John Salerno wrote:
Carsten Haese wrote:
>[id] [university] [yearStart] [yearEnd] [degreeEarned]
1 U of I 1971 1975 BS
1 U of I 1975 1976 MS
1 U of I 1976 1977 PhD

Thanks guys. I do plan to have an id entry for each person as well, I
just forgot to mention that. But since it's a primary key, I didn't know
I could list it more than once. Or does primary key not necessarily mean
unique?
Primary key *does* mean unique in the table that defines it. However, if
you take a primary key ID from one table and store it in a different
table, that's a foreign key. There are no inherent uniqueness
constraints on a foreign key.

So in the example above, isn't that using the same primary key multiple
times in the same table?
Actually, the [id] in the example was intended to be the
foreign key, I didn't specify an id for the degree records
themselves. A more typical example would be

[Eid] [Sid] [university] [yearStart] [yearEnd] [degreeEarned]
5 1 U of I 1971 1975 BS
6 1 U of I 1975 1976 MS
7 1 U of I 1976 1977 PhD

where [Eid] is the primary key of the Education table and
[Sid] is the foreign key from the Student table so that the
single student record (1) links to three education records
(5,6,7).

Oct 20 '06 #12
me********@aol.com wrote:
[Eid] [Sid] [university] [yearStart] [yearEnd] [degreeEarned]
5 1 U of I 1971 1975 BS
6 1 U of I 1975 1976 MS
7 1 U of I 1976 1977 PhD

where [Eid] is the primary key of the Education table and
[Sid] is the foreign key from the Student table so that the
single student record (1) links to three education records
(5,6,7).
Hmmm. I think I'm lost. My table will have a key that represents the
persons ID, in my case it would be salerjo01. This will be what ties
this table to that person. Can I repeat this key multiple times in the
Education table?
Oct 20 '06 #13
John Salerno wrote:
me********@aol.com wrote:
[Eid] [Sid] [university] [yearStart] [yearEnd] [degreeEarned]
5 1 U of I 1971 1975 BS
6 1 U of I 1975 1976 MS
7 1 U of I 1976 1977 PhD

where [Eid] is the primary key of the Education table and
[Sid] is the foreign key from the Student table so that the
single student record (1) links to three education records
(5,6,7).

Hmmm. I think I'm lost. My table will have a key that represents the
persons ID, in my case it would be salerjo01. This will be what ties
this table to that person. Can I repeat this key multiple times in the
Education table?
Yes, because it would be a foreign key.

Perhaps a simple example might help:

import sqlite3

con = sqlite3.connect(":memory:")
cur = con.cursor()

# in the [person] table, [personid] is the primary key
# but in the [education] table, it's a foreign key
# I deliberately didn't make them AUTOINCREMENT to
# simplify the example
cur.executescript("""
create table person(
personid PRIMARY KEY,
firstname,
lastname
);

create table education(
educationid PRIMARY KEY,
personid,
institution,
yearStart,
yearEnd,
degreeEarned
);
""")

persons = [(1,'Tom','Smith'), \
(2,'Dick','Smith'), \
(3,'Harry','Smith')]

degrees = [(1,1,'University of Illinois',1971,1975,'BS'), \
(2,1,'University of Illinois',1975,1976,'MS'), \
(3,1,'University of Illinois',1976,1977,'PhD'), \
(4,2,'University of Illinois',1971,1974,None), \
(5,2,'DeVry Institute of Technology',1974,1976,'ASEET')]

cur.executemany("""
INSERT INTO person(personid,
firstname,
lastname)
VALUES (?,?,?)"""
, persons)

cur.executemany("""
INSERT INTO education(educationid,
personid,
institution,
yearStart,
yearEnd,
degreeEarned)
VALUES (?,?,?,?,?,?)"""
, degrees)
# Note: since both tables have a field named [personid],
# the table name must be included when referencing
# that field
cur.execute("""
SELECT firstname,
lastname,
institution,
yearStart,
yearEnd,
degreeEarned
FROM education
INNER JOIN person
ON person.personid = education.personid
ORDER BY education.personid;
""")

report = cur.fetchall()
for i in report:
print '%5s %-5s %-30s %d-%d %-6s' % (i)

## Tom Smith University of Illinois 1971-1975 BS
## Tom Smith University of Illinois 1975-1976 MS
## Tom Smith University of Illinois 1976-1977 PhD
## Dick Smith University of Illinois 1971-1974 None
## Dick Smith DeVry Institute of Technology 1974-1976 ASEET

## Note that the third person, Harry Smith, doesn't show up
## in the report.
## That's because no education records were created for him.
## When you do an INNER JOIN between two tables, the linking field,
## [personid] must exist in both tables.

Oct 20 '06 #14

me********@aol.com wrote:
John Salerno wrote:
me********@aol.com wrote:
[Eid] [Sid] [university] [yearStart] [yearEnd] [degreeEarned]
5 1 U of I 1971 1975 BS
6 1 U of I 1975 1976 MS
7 1 U of I 1976 1977 PhD
>
where [Eid] is the primary key of the Education table and
[Sid] is the foreign key from the Student table so that the
single student record (1) links to three education records
(5,6,7).
>
Hmmm. I think I'm lost. My table will have a key that represents the
persons ID, in my case it would be salerjo01. This will be what ties
this table to that person. Can I repeat this key multiple times in the
Education table?

Yes, because it would be a foreign key.

Perhaps a simple example might help:

import sqlite3

con = sqlite3.connect(":memory:")
cur = con.cursor()

# in the [person] table, [personid] is the primary key
# but in the [education] table, it's a foreign key
# I deliberately didn't make them AUTOINCREMENT to
# simplify the example
cur.executescript("""
create table person(
personid PRIMARY KEY,
firstname,
lastname
);

create table education(
educationid PRIMARY KEY,
personid,
institution,
yearStart,
yearEnd,
degreeEarned
);
""")

persons = [(1,'Tom','Smith'), \
(2,'Dick','Smith'), \
(3,'Harry','Smith')]

degrees = [(1,1,'University of Illinois',1971,1975,'BS'), \
(2,1,'University of Illinois',1975,1976,'MS'), \
(3,1,'University of Illinois',1976,1977,'PhD'), \
(4,2,'University of Illinois',1971,1974,None), \
(5,2,'DeVry Institute of Technology',1974,1976,'ASEET')]

cur.executemany("""
INSERT INTO person(personid,
firstname,
lastname)
VALUES (?,?,?)"""
, persons)

cur.executemany("""
INSERT INTO education(educationid,
personid,
institution,
yearStart,
yearEnd,
degreeEarned)
VALUES (?,?,?,?,?,?)"""
, degrees)
# Note: since both tables have a field named [personid],
# the table name must be included when referencing
# that field
cur.execute("""
SELECT firstname,
lastname,
institution,
yearStart,
yearEnd,
degreeEarned
FROM education
INNER JOIN person
ON person.personid = education.personid
ORDER BY education.personid;
""")

report = cur.fetchall()
for i in report:
print '%5s %-5s %-30s %d-%d %-6s' % (i)

## Tom Smith University of Illinois 1971-1975 BS
## Tom Smith University of Illinois 1975-1976 MS
## Tom Smith University of Illinois 1976-1977 PhD
## Dick Smith University of Illinois 1971-1974 None
## Dick Smith DeVry Institute of Technology 1974-1976 ASEET

## Note that the third person, Harry Smith, doesn't show up
## in the report.
## That's because no education records were created for him.
## When you do an INNER JOIN between two tables, the linking field,
## [personid] must exist in both tables.
If you actually DO want to see Harry Smith listed in the
report even though he has no education, you would change
the INNER JOIN to a RIGHT JOIN. But sqlite3 doesn't
support RIGHT JOIN, only LEFT JOIN. So we just have
to change the direction of the JOIN. Instead of from
education to person, make it it from person to
education and then we can use LEFT JOIN. And it might
be a good idea to sort on person.personid since
education.personid will be null if there is no matching
record.

The modified query becomes:

cur.execute("""
SELECT firstname,
lastname,
institution,
yearStart,
yearEnd,
degreeEarned
FROM person
LEFT JOIN education
ON person.personid = education.personid
ORDER BY person.personid;
""")

And I had to change the print statement since nulls
(which translate to None) crash the %d. With that
change we now can see ALL the people and note
that Harry is uneducated.

Tom Smith University of Illinois 1971-1975 BS
Tom Smith University of Illinois 1975-1976 MS
Tom Smith University of Illinois 1976-1977 PhD
Dick Smith University of Illinois 1971-1974 None
Dick Smith DeVry Institute of Technology 1974-1976 ASEET
Harry Smith None None-None None

Oct 20 '06 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: RC | last post by:
I have an Access 2002 database with many tables and forms (but just to keep things simple, let's say the DB has one Table "Table1" and one Form "Form1"). I have managed to cobble together so much...
8
by: rdemyan via AccessMonster.com | last post by:
I've converted my application from A2K format to A2003 format. I tried to follow Allen Browne's protocol in getting my app into A2003 (although I was unable to find informtion on the conversion...
2
by: syntego | last post by:
We commonly use triggers to log changes to our main tables to historical log tables. In the trigger, we create a concatenated string of the old values by casting them as follows: ...
3
by: AA Arens | last post by:
I created at a Word filke containing field and the data is from my database (via ODBC). One of the fields is Date. The format in the database is dd-mm-yyyy (I checked it in VB code), but in the...
9
by: RMC | last post by:
Hello, I'm looking for a way to parse/format a memo field within a report. The Access 2000 database (application) has an equipment table that holds a memo field. Within the report, the memo...
2
by: savigliano | last post by:
hello, i am doing a date comparation and i have reallize that the data i have in my database (general date format) it is causing me problems, and because i don´t need the time data i would like to...
3
by: Alfred | last post by:
I want to post text field data from these HTML TEXTAREA tags to a PostgreSQL database and have it reappear back on another page exactly as I had typed it. Over the years I have done this but only...
10
by: ARC | last post by:
Hello all, General question for back-end database that has numerous date fields where the database will be used in regions that put the month first, and regions that do not. Should I save a...
22
by: sivadhanekula | last post by:
Hello Everyone A quick and direct question: I need a C/C++ program to extract the data from the database and the output should be in CSV "Comma Separated Value" format. Briefly: I will be given a...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.