A: 

This isn't a database design issue. It's a UI issue.

The Drop down list of universities is based on rows in a table. That table must have a new row inserted when the user types in a new University to the text box.

If you want to separate the list you provided from the ones added by users, you can have a column in the University table with origin (or provenance) of the data.

S.Lott
Not such a bad idea. I think that I'd use a separate table for user entered data. Use a flag in the original to mark which. Keep a count in the user-entered table of times entered. Periodically, you could have a maintenance task that would take anything entered more than once and move it.
tvanfosson
Or if there aren't many entries or you are concerned with bogus entries (University of Okiboji), they could just be scanned by eye and processed manually.
tvanfosson
@tvanhfosson: separate table never works out well -- you have endless union queries to merge up the two data sets. One table with status flags is simpler in the long run.
S.Lott
+1  A: 

Keep a flag for the rows entered through user input in the same table as you have your other data points. Then you can sort using the flag.

Learning
A: 

I'm not sure if the question is very clear here.

I've done this quite a few times at work and just select between either the drop down list of a text box. If the data is entered in the text box then I first insert into the database and then use IDENTITY to get the unique identifier of that inserted row for further queries.

INSERT INTO MyTable Name VALUES ('myval'); SELECT @@SCOPE_IDENTITY()

This is against MS SQL 2008 though, I'm not sure if the @@SCOPE_IDENTITY() global exists in other versions of SQL, but I'm sure there's equivalents.

Kezzer
but how then can I handle if multiple users enter the same university name? Should I first check if their custom input matches a university in the database?
sabbour
Make the university name column unique, that way the query will fail if they enter the same name. The unique property is a SQL feature which you can apply to the column in the database to stop duplicate entries being entered.
Kezzer
+4  A: 
CREATE TABLE university
(
  id smallint NOT NULL,
  name text,
  public smallint,
  CONSTRAINT university_pk PRIMARY KEY (id)
);

CREATE TABLE person
(
  id smallint NOT NULL,
  university smallint,
  -- more columns here...
  CONSTRAINT person_pk PRIMARY KEY (id),
  CONSTRAINT person_university_fk FOREIGN KEY (university)
      REFERENCES university (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION
);

public is set to 1 for the Unis in the system, and 0 for user-entered-unis.

svinto
this is what I thought of, but I wanted to know whether it is actually done this way!
sabbour
I'd say it is, as it's simpler than the alternatives.
svinto
It needs a garbage collector though, else this scheme might end up having many orphaned entries in `university`.
David Schmitt
Also have to think of when a user entered university becomes a system university. Just change the value.. but don't want duplicates in case an admin isn't looking for already existing entries.
Arthur Thomas
Yes, how can this be automated as much as possible?
sabbour
Garbage collecting is as simple as DELETE FROM university WHERE public = 0 AND id NOT IN (SELECT DISTINCT university FROM person)
svinto
+1  A: 

One way this was solved in a previous company I worked at:

Create two columns in your table: 1) a nullable id of the system-supplied string (stored in a separate table) 2) the user supplied string

Only one of these is populated. A constraint can enforce this (and additionally that at least one of these columns is populated if appropriate).

It should be noted that the problem we were solving with this was a true "Other:" situation. It was a textual description of an item with some preset defaults. Your situation sounds like an actual entity that isn't in the list, s.t. more than one user might want to input the same university.

Giraffe
this might be another question but isn't storing NULL values in the rows a bad thing to do?
sabbour
Yes exactly, I want to know how Facebook handles this situation when a user modifies their profile to input Work information or Education information!
sabbour
@NULLs in rows: as long as you're expecting them, no
David Schmitt
+1  A: 

You could cheat: if you're not worried about the referential integrity of this field (i.e. it's just there to show up in a user's profile and isn't required for strictly enforced business rules), store it as a simple VARCHAR column.

For your dropdown, use a query like:

SELECT DISTINCT(University) FROM Profiles

If you want to filter out typos or one-offs, try:

SELECT University FROM PROFILES
GROUP BY University
HAVING COUNT(University) > 10  -- where 10 is an arbitrary threshold you can tweak

We use this code in one of our databases for storing the trade descriptions of contractor companies; since this is informational only (there's a separate "Category" field for enforcing business rules) it's an acceptable solution.

Keith Williams