Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Erland Sommarskog Newsgroups: comp.databases.ms-sqlserver Subject: Re: how to insert values in two table with single query Date: Thu, 24 Nov 2011 13:53:25 +0000 (UTC) Organization: Erland Sommarskog Lines: 28 Message-ID: References: <3dd607ca-010c-4e49-bde8-cef2d1ec603d@z22g2000prd.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Date: Thu, 24 Nov 2011 13:53:25 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="G7+Jz22XqYCG8C6rb1H3YA"; logging-data="26104"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX196M2khhl0skPYycmhwiaF+" User-Agent: Xnews/2005.10.03 Mime-proxy/1.4.c.4 (Win32) Cancel-Lock: sha1:tqGjnRcTlQ7qqlz7BBw5QXAcZRk= Xref: x330-a1.tempe.blueboxinc.net comp.databases.ms-sqlserver:838 Pab (prabu.net88@gmail.com) writes: > i am trying to insert data two table with single query with > foreign key reference but its not working > my query is > BEGIN TRANSACTION > DECLARE @salid int > Insert into sal_products (upc,shelf_number,aisle_no) values > ('123asd','N/A','N/A','N/A','N/A',100) > select @salid = scope_identity() > insert into sal_product_locations (sal_product_id,side,position) > values (@salid,'N/A','N/A') > commit > could any one provide me solution for this What does "not working" mean? Do you get unexpected results? Do you get an error message? In such case, please share it. Something else? A quick look indicates that in the first INSERT statement you list three columns and five values. That is not going to work out. -- Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se Books Online for SQL Server 2005 at http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx