How to insert values into existing SQL Server tables with foreign keys

大城市里の小女人 提交于 2019-12-02 12:20:12

Given the structure, I think you need two inserts and an update:

  1. Insert a new department with a NULL manager.
  2. Insert the manager in the employees table.
  3. Update the department with the manager's id.

Deferred constraint will help solving this case without the need of inserting null value rows. But only Postgresql and Oracle supports this kind of constraint. On using the DEFERRABLE keyword, constraint will be enforced only at the time of transaction commit. Unfortunately sql server is not supporting this constraint.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!