473,320 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

insert into 2 sql tables

Is there a way to insert data into 2 tables but use the ID from table 1 and
insert that into table 2 as well as several other values?

so I can insert a ID into table1, I then need that ID and insert that with
the records into table2.
I'm not using a a stored procedure, I'm using inline sql statements.

should I do the insert first then do a select on table1 and use that
parameter or is there another way to do this?
May 1 '07 #1
5 6913
You say you aren't using stored procs, are you able to put a trigger
on table1 to do the table 2 stuff?
May 1 '07 #2
mac
On May 1, 4:09 pm, "GotDotNet?" <csharpco...@optonline.netwrote:
Is there a way to insert data into 2 tables but use the ID from table 1 and
insert that into table 2 as well as several other values?

so I can insert a ID into table1, I then need that ID and insert that with
the records into table2.
I'm not using a a stored procedure, I'm using inline sql statements.

should I do the insert first then do a select on table1 and use that
parameter or is there another way to do this?
SELECT scope_identity()

after your INSERT statement into the first table.

May 1 '07 #3
No, because I'm working with Sql CE
"owen79" <ow*********@googlemail.comwrote in message
news:11**********************@o5g2000hsb.googlegro ups.com...
You say you aren't using stored procs, are you able to put a trigger
on table1 to do the table 2 stuff?


May 1 '07 #4
that won't work becaue the identity column is not the id field I need. I'm
generating a GUID that I need to all the tables for an ID field.
"mac" <kb********@gmail.comwrote in message
news:11********************@q75g2000hsh.googlegrou ps.com...
On May 1, 4:09 pm, "GotDotNet?" <csharpco...@optonline.netwrote:
>Is there a way to insert data into 2 tables but use the ID from table 1
and
insert that into table 2 as well as several other values?

so I can insert a ID into table1, I then need that ID and insert that
with
the records into table2.
I'm not using a a stored procedure, I'm using inline sql statements.

should I do the insert first then do a select on table1 and use that
parameter or is there another way to do this?

SELECT scope_identity()

after your INSERT statement into the first table.

May 1 '07 #5

Write out the basic DDL please.

Are you using Guid's for the primary key? Or using IDENTITY's?
Dept
_____
DeptUUID , DeptName
Emp
_____
EmpUUID , EmpName , EmpDeptUUID
Are you creating a Dept, and then trying to create an Emp, but you need the
DeptUUID for the (fk) EmpDeptUUID ?

Something like that?


"GotDotNet?" <cs*********@optonline.netwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
that won't work becaue the identity column is not the id field I need. I'm
generating a GUID that I need to all the tables for an ID field.
"mac" <kb********@gmail.comwrote in message
news:11********************@q75g2000hsh.googlegrou ps.com...
On May 1, 4:09 pm, "GotDotNet?" <csharpco...@optonline.netwrote:
Is there a way to insert data into 2 tables but use the ID from table 1
and
insert that into table 2 as well as several other values?

so I can insert a ID into table1, I then need that ID and insert that
with
the records into table2.
I'm not using a a stored procedure, I'm using inline sql statements.

should I do the insert first then do a select on table1 and use that
parameter or is there another way to do this?
SELECT scope_identity()

after your INSERT statement into the first table.


May 1 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: EricRobineau | last post by:
hello I have a DB with many inter-related tables (MySQL) My main table called "content" has almost only foreign keys (integers) some have a 3 level relation (ex: content->city->region->country) ...
14
by: serge | last post by:
I have a scenario where two tables are in a One-to-Many relationship and I need to move the data from the Many table to the One table so that it becomes a One-to-One relationship. I need to...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
16
by: robert | last post by:
been ruminating on the question (mostly in a 390/v7 context) of whether, and if so when, a row update becomes an insert/delete. i assume that there is a threshold on the number of columns of the...
6
by: Larry Johnson | last post by:
I have two similar SQL Server databases each with a table named Payments. PaymentID is an identity field and the primary, unique, key in both tables. There is one other key but it is not unique. ...
8
by: Carl | last post by:
Hi, I hope someone can share some of their professional advice and help me out with my embarissing problem concerning an Access INSERT query. I have never attempted to create a table with...
2
by: RSH | last post by:
I have a rather simple script that transfers data from a SQL server database to an Access database. The procedure is intended to be dynamic so I am basically adding a datarow and then passing the...
8
by: nano2k | last post by:
Hi Shortly, I keep invoices in a table. Occasionally, someone will fire the execution of a stored procedure (SP) that performs several UPDATEs against (potentially) all invoices OLDER than a...
3
by: nolanmadson | last post by:
I'm creating a front-end for some Teradata user maintenance tables in MS Access. I've started having problems in occasionally not being able to insert or update records in these tables. I've been...
0
chumlyumly
by: chumlyumly | last post by:
Hello scripters - OS: Mac OSX Language: PHP w/ MySQL database I've created an insert page where a user inputs his info, which then goes to four different tables in a MySQL database. The...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.