Adding a foreign key constraint without losing the current data I have one table called users and another table called teachers (the users table has data in it).

I want to add a column to teachers with a foreign key constraint making a reference to a column named id in the users table.

How can I do that without losing the rows contained in the users table?
Why would you lose the rows in the users table when you add a column to it? The rows just get initialized with a null value.  After you place the foreign key constraint, future rows with that column set to non-null get checked against the table the column references.

There are three ways for you to lose rows.


DELETE
TRUNCATE
DROP TABLE