Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 28th, 2007, 10:52 PM
Authorized User
 
Join Date: Jan 2007
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default setting the value of FK

Hello,
I have tables which have relation. I want to know how can I set the PK value of table A which is the FK of table B while I can’t have “SET IDENTITY_INSERT BATTERY ON” for two table at one time?
Thank you,
 
Old March 8th, 2007, 01:50 PM
Authorized User
 
Join Date: Oct 2005
Location: , , .
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You don't need to set the IDENTITY_INSERT on the second table, only the first one because this table contains the primary key. But if you are also going to insert into the second table and setting the primary key, here's what you need to do:

1. SET IDENTITY_INSERT <Table1> ON
2. INSERT INTO <Table1>
3. SET IDENTITY_INSERT <Table2> ON
4. INSERT INTO <Table2>

SQL Server Helper
How well do you know SQL? Find out with the free test assessment from SQL Server Helper!!!
http://www.sql-server-helper.com/free-test/default.aspx

Got a SQL Server Question? Ask us here: http://www.sql-server-helper.com/forums/default.asp




Similar Threads
Thread Thread Starter Forum Replies Last Post
Null and FK scandalous SQL Server 2005 1 March 28th, 2007 03:40 PM
setting the value of FK csharpa .NET Framework 2.0 0 February 28th, 2007 10:53 PM
setting the value of FK csharpa ADO.NET 0 February 28th, 2007 10:50 PM
Setting up IIS dfrancis BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 12 November 5th, 2006 03:36 PM
Passing and Setting a new Value tammy Classic ASP Databases 2 April 6th, 2004 02:43 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.