Note that there are some explanatory texts on larger screens.

plurals
  1. POConflict at update/insert on table which has nvarchar indexed relationship
    primarykey
    data
    text
    <p>I have tables on sql server like below:</p> <pre><code>:: LG_STATUSES - code / nvarchar(50) - name / nvarchar(100) - description / nvarchar(250) :: LG_PACKAGES - LOGICALREF / int - PersonnelRef / int - lgStatusCode / nvarchar(50) // and some other columns which are not related to current problem </code></pre> <p>Lines of Statuses table:</p> <pre><code>code name description ------------------------------------------------------------ approved onaylandı NULL draft taslak NULL inApproval onay sürecinde NULL </code></pre> <p>When I create relationship between these two tables (Statuses.code &amp; Packages.lgStatusCode) by using Microsoft SQL Server Management Studio, there is no error. Relationship is created without problem. But when I try to insert new lines or update current line on Packages table by changing lgStatusCode</p> <pre><code>UPDATE [dbo].[LG_PACKAGES] SET [lgStatusCode] = 'draft' WHERE LOGICALREF = 101 </code></pre> <p>an error occured like below:</p> <pre><code>The UPDATE statement conflicted with the FOREIGN KEY constraint "FK_LG_PACKAGES_LG_STATUSES". The conflict occurred in database "PackageManagement", table "dbo.LG_STATUSES", column 'code'. </code></pre> <p>I couldn't figure out the problem. 'draft' status is also exist in LG_STATUSES table. Does the error occurs because of using string (nvarchar) on relationship? Is this invalid usage?</p> <p>Thanks.</p> <p>Edit: SQL Contraint Definition</p> <pre><code>ALTER TABLE [dbo].[LG_PACKAGES] WITH CHECK ADD CONSTRAINT [FK_LG_PACKAGES_LG_STATUSES] FOREIGN KEY([lgStatusCode]) REFERENCES [dbo].[LG_STATUSES] ([code]) GO ALTER TABLE [dbo].[LG_PACKAGES] CHECK CONSTRAINT [FK_LG_PACKAGES_LG_STATUSES] GO </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload