Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Update table where there is FOREIGN KEY reference


Update table where there is FOREIGN KEY reference

Author
Message
Smash125
Smash125
SSC Veteran
SSC Veteran (217 reputation)SSC Veteran (217 reputation)SSC Veteran (217 reputation)SSC Veteran (217 reputation)SSC Veteran (217 reputation)SSC Veteran (217 reputation)SSC Veteran (217 reputation)SSC Veteran (217 reputation)

Group: General Forum Members
Points: 217 Visits: 1381
Want to update t4 table
but update fails as there is relationship between tables. Right there is one to many relationship between T3 and T4

CREATE TABLE T3
(
FirstName NVARCHAR(255),
MiddleName NVARCHAR(255),
LastName NVARCHAR(255),
ContactID INT,
CONSTRAINT pk_T3_pid PRIMARY KEY(ContactID)
)
GO
CREATE TABLE T4
(
ContactID INT,
SalesOrderID INT,
TotalDue MONEY,
CONSTRAINT pk_T4_sid PRIMARY KEY(SalesOrderID),
CONSTRAINT fk_T4_sid FOREIGN KEY(ContactID) REFERENCES T3(ContactID)
)
GO

I want to update T4 table for ContactID= 1 where i want to update SalesOrderID and TotalDue

How to go ahead with this kind of update
SomewhereSomehow
SomewhereSomehow
SSC Journeyman
SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)

Group: General Forum Members
Points: 96 Visits: 469
You may disable constraint like that
alter table dbo.T4 nocheck constraint fk_T4_sid
and do what you want, but, be aware of performance problems. I blogged about it here (unfortunatelly it is only in russian, but t-sql and plans talk for them selfes).
To have all the benefits of FK, your FK should be trusted, that means, that there should be a solid integrity of data and no missing values of fk column for pk.


I am really sorry for my poor gramma. And I hope that value of my answers will outweigh the harm for your eyes.
Blog: http://somewheresomehow.ru
Twitter: @SomewereSomehow
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search