SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 NULL in foreign key
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

desikankannan
Posting Yak Master

India
152 Posts

Posted - 11/19/2013 :  08:04:34  Show Profile  Send desikankannan a Yahoo! Message  Reply with Quote
Hi,
I want to insert NULL value in foreign key reference, my field name is
fid i try to insert NULL value to this field did = '' below find my query


UPDATE DeathData SET FirstName = 'Jack', MiddleName = '', LastName = 'Brown', Title = '', BirthDate = '2/1/1933', DeathDate = '7/30/2008', VisitationLocation = 'Mowery Funeral Service', VisitationDate = '8/1/2008', VisitationTime = '1:00 p.m.-8:00 p.m. ', FuneralDate = '8/2/2008', FuneralTime = '10:00 a.m.', ObitText = 'Public', ObitPhoto = 'obitphotos/brownjack.jpg', BurialTime = '', FuneralType = 'Public', BurialType = 'Public', Note = '', DisplayOnWebsite = 'Y', fid = '46', bid = '294', did = '' WHERE ID = 29


error message

Msg 547, Level 16, State 0, Line 1
The UPDATE statement conflicted with the FOREIGN KEY constraint "FK_Donations". The conflict occurred in database "Moweryfinal", table "dbo.tbldonations", column 'did'.
The statement has been terminated.

Desikankannan

James K
Flowing Fount of Yak Knowledge

3585 Posts

Posted - 11/19/2013 :  08:14:57  Show Profile  Reply with Quote
You need to have a row with the value of '' in the did column of the referring dbo.tbldonations table.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 11/19/2013 :  09:09:12  Show Profile  Reply with Quote
'' is not same as NULL
'' means blank value
whereas NULL means unknown value. Its not stored internally as a value in SQL Server. It just represents condition unknown value
to set it to NULL you need to explicitly pass it as

did = NULL and not
did = ''

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000