hello everyone. i'm a newbie to ms sql but i understand the basics of adding tables and linking them. i have two tables tables that i have linked; Department and Employee. The Department table is the main table with a foreign key in the Employee table.
now from by basic understanding, if i'm to input data into the Department table and then input data in the Employee table, the foreign key 'Department_id' in the Employee table should automatically fill up, right?
well it keeps telling me that i can't leave that field null, but i can't manually fill in the data too. what am i doing wrong. can anyone help?

8 Years
Discussion Span
Last Post by tryongliph

I dont use MS Sql anymore, but as far as I can remember the data will NOT be automatically inserted. You have to insert the data.

There has to be data in the table which references the foreign key, so in your case the department table has to have valid data. Then when inserting records into the Employee table the correct department id must be used.

I suspect that u cannot insert records into the employee table as u dont have any records in the department table.

Edited by Thirusha: n/a


yeah, i discovered that later to my greatest disappointment, they should make it automatic though. thanks for the help.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.