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?

Recommended Answers

All 2 Replies

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.