﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / T-SQL (SS2K8)  / Best way to insert into two related tables? / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 22 May 2013 14:09:59 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Best way to insert into two related tables?</title><link>http://www.sqlservercentral.com/Forums/Topic1420502-392-1.aspx</link><description>[quote][b]drew.allen (2/19/2013)[/b][hr][quote][b]Jeff Moden (2/15/2013)[/b][hr][quote][b]OTF (2/15/2013)[/b][hr]You can also take a look at using OUTPUT.[/quote]I've found that to be a wee bit more difficult than you would think unless you have an alternate key to reliably express the new value across the other tables.With that thought in mind, do you have a coded example of how to do this?[/quote]This used to be true in SQL 2005, but it's no longer true as of SQL 2008.  I'll work on writing up an article in the next few days.Drew[/quote]Very cool.  I'd love to see it, Drew.  In fact, if you'd like, I'll be happy to do a technical review on it, if you'd like.</description><pubDate>Tue, 19 Feb 2013 16:13:41 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Best way to insert into two related tables?</title><link>http://www.sqlservercentral.com/Forums/Topic1420502-392-1.aspx</link><description>[quote][b]Jeff Moden (2/15/2013)[/b][hr][quote][b]OTF (2/15/2013)[/b][hr]You can also take a look at using OUTPUT.[/quote]I've found that to be a wee bit more difficult than you would think unless you have an alternate key to reliably express the new value across the other tables.With that thought in mind, do you have a coded example of how to do this?[/quote]This used to be true in SQL 2005, but it's no longer true as of SQL 2008.  I'll work on writing up an article in the next few days.Drew</description><pubDate>Tue, 19 Feb 2013 14:45:58 GMT</pubDate><dc:creator>drew.allen</dc:creator></item><item><title>RE: Best way to insert into two related tables?</title><link>http://www.sqlservercentral.com/Forums/Topic1420502-392-1.aspx</link><description>Create store procedure that retrieve data that inserted in violation table and then insert it to the other table. matter of execution sequence..</description><pubDate>Fri, 15 Feb 2013 20:39:28 GMT</pubDate><dc:creator>math martinez</dc:creator></item><item><title>RE: Best way to insert into two related tables?</title><link>http://www.sqlservercentral.com/Forums/Topic1420502-392-1.aspx</link><description>How many violations are needing to be submitted at one time from the front-end? Or are you passing them to the database one-at-a-time? I am thinking table-valued parameters may be useful here to pass the data...but that is sort of an aside to the question being asked.If it's one violation per call then SCOPE_IDENTITY() might be all you need. If it's more than that OUTPUT could most likely help you. Can you provide the DDL for the tables and sample data that you would send to the database that you would want committed to the four tables and linked accordingly?</description><pubDate>Fri, 15 Feb 2013 16:13:09 GMT</pubDate><dc:creator>opc.three</dc:creator></item><item><title>RE: Best way to insert into two related tables?</title><link>http://www.sqlservercentral.com/Forums/Topic1420502-392-1.aspx</link><description>[quote][b]OTF (2/15/2013)[/b][hr]You can also take a look at using OUTPUT.[/quote]I've found that to be a wee bit more difficult than you would think unless you have an alternate key to reliably express the new value across the other tables.With that thought in mind, do you have a coded example of how to do this?</description><pubDate>Fri, 15 Feb 2013 15:18:05 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Best way to insert into two related tables?</title><link>http://www.sqlservercentral.com/Forums/Topic1420502-392-1.aspx</link><description>You can also take a look at using OUTPUT.</description><pubDate>Fri, 15 Feb 2013 08:19:52 GMT</pubDate><dc:creator>OTF</dc:creator></item><item><title>RE: Best way to insert into two related tables?</title><link>http://www.sqlservercentral.com/Forums/Topic1420502-392-1.aspx</link><description>In one sproc, maybe make use of [url=http://msdn.microsoft.com/en-gb/library/ms190315(v=sql.105).aspx]Scope_identity()[/url]?</description><pubDate>Fri, 15 Feb 2013 06:47:29 GMT</pubDate><dc:creator>Cadavre</dc:creator></item><item><title>Best way to insert into two related tables?</title><link>http://www.sqlservercentral.com/Forums/Topic1420502-392-1.aspx</link><description>Hi, My front end has a form that allows the user to input informationI have the following tables:ViolationsFinancialsChecksCourt datesMy violations table has a primary key Violation_IDthe other tables have a foreign key V_ID The form where the user inputs the data contains fields for all the tablesWhat I'm trying to do is when I do an insert it will populate all V_ID fields with the violation_ID from the violations table but the Violation_ID field is an identity field so I wouldn't have a value to populate the V_ID field in the other tables until after the data that goes into the Violations table is insertedWhat's the best way to accomplish this?Thanks in Advance</description><pubDate>Fri, 15 Feb 2013 06:33:56 GMT</pubDate><dc:creator>Patrick Hill-489170</dc:creator></item></channel></rss>