SQL guys - what to use for a unique key?

notfred

Lifer
Feb 12, 2001
38,241
4
0
I'm setting up a table to keep track of employee information - name, phone, email, etc. However, there's always the possiblity that we could hire two John Smiths, and not everyone necesarily has an email address. What should I use for a unique identifier? Should I create an "employee number" column?
 

iamwiz82

Lifer
Jan 10, 2001
30,772
13
81
If it is going to be a somewhat public number, give them each a unique number, for purely sorting or identifying, SSN is fine.
 

Ameesh

Lifer
Apr 3, 2001
23,686
1
0
a unique key is nice so there is a way to search down to one entry and no exact duplicates records can e made.

Internally databases use keys to find and correlate data when do quieres.


Most modern DBs have an option to create a autonumber so everytime a new entry is made it will put another number into thta column, many people like have that as their primary key.
 

kranky

Elite Member
Oct 9, 1999
21,020
156
106
SSN is always an easy way out because it's a piece of information the company already has. You can go with the employee number method, but that's another piece of data to track.
 

Cerebus451

Golden Member
Nov 30, 2000
1,425
0
76
I would second using the SSN if it is available. If not then you will have to use some sort of employee id, which may already exist. At our office we use initials as a key and modify the middle initial when a duplicate occurs (for instance, my initials are JBM, if someone else joined the company with those same initials they would get JXM, the JYM). This only really works for a small company like ours.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
I dn't think it's necessary to have SSN in this table (it's jsut for contact information) so I think I'll just use an arbitrary value that's incremented everytime a new employee is added.
 

PsychoAndy

Lifer
Dec 31, 2000
10,735
0
0
Originally posted by: notfred
I dn't think it's necessary to have SSN in this table (it's jsut for contact information) so I think I'll just use an arbitrary value that's incremented everytime a new employee is added.

SSN may not be a good choice. How many people have access and how secure is the data? If its being stored with personal info and it gets into the wrong hands...well you can figure it out.

Perhaps a phone number may work. How many John Smiths's live togehter?

-PAB
 

iamwiz82

Lifer
Jan 10, 2001
30,772
13
81
Originally posted by: PsychoAndy
Originally posted by: notfred
I dn't think it's necessary to have SSN in this table (it's jsut for contact information) so I think I'll just use an arbitrary value that's incremented everytime a new employee is added.

SSN may not be a good choice. How many people have access and how secure is the data? If its being stored with personal info and it gets into the wrong hands...well you can figure it out.

Perhaps a phone number may work. How many John Smiths's live togehter?

-PAB

well, John and I do...

:eek:
 

trmiv

Lifer
Oct 10, 1999
14,670
18
81
The company I work for makes DB software that is used to track employees (among many other things). Or software has the ability to use any field as a unique ID, but by far the most common for any company we install at is using an autonumber.

Phone is rarely an option because their can be employees who don't have a phone, but work in a department with a common phone number (you know, call up, "Hey is John Smith there?"). I also rarely see SSN.
 

manly

Lifer
Jan 25, 2000
13,569
4,234
136
Originally posted by: notfred
I dn't think it's necessary to have SSN in this table (it's jsut for contact information) so I think I'll just use an arbitrary value that's incremented everytime a new employee is added.
SSN is known as a natural primary key, but as you said, it's not appropriate for all data models. In fact, I think some states have legislation these days specifically covering acceptable handling of SSN because there's so much identity fraud out there.

Like Ameesh said, most databases will auto-generate an integer primary key value for you.
 

AU Tiger

Diamond Member
Dec 26, 1999
4,280
0
76
SSN is not a good idea for a database unless it is secured. I recently finished working at a large company that still used SSN for tracking their employees and they are moving towards an employee id since many employees have expressed concern about their SSN being available on reports and in the many applications that deal with employees.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
I set it up with auto_increment to automatically generate a key for me (had to look that up).