473,323 Members | 1,537 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,323 software developers and data experts.

How do I Insert Data into Multple Tables

hi

i'm new to sql
i know some basics

i have to insert a value in multiple tables somthing like
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO table1(col1,col2)
  2. value(val1,val2)
  3. INSERT INTO table2(col1,col2)
  4. value(val1,val2)
and i now need to insert an id from table1 into table 2
the id in table 1 is an autonumber but not in table 2 int table

hopefuly its explaind enough

how do i do this in acces and sql server 2008
Feb 6 '12 #1
3 1782
NeoPa
32,556 Expert Mod 16PB
The answer is fundamentally the same for SQL Server (T-SQL) as it is for Access. You need to be able to identify uniquely (and you don't give any such details in your question) the records that you've added with the first INSERT INTO SQL, then use this reference to filter these same records from the first table and append them into the second table.

INSERT INTO has an alternative format where data is provided from other tables rather than a value list, as in your example.
Feb 6 '12 #2
Mihail
759 512MB
I can't understand how NeoPa had forgot to put this link
http://bytes.com/topic/access/insigh...ble-structures
for you. (you know me, NeoPa: I can't be all time very seriously :) )
That because I can't see any reason to store the same values in two different tables. Maybe I am wrong this time, but I don't think so.
Feb 7 '12 #3
NeoPa
32,556 Expert Mod 16PB
It's worth mentioning Mihail, certainly. There are situations where this could be fully conformant with Normalisation theory though. After all, we have so little information to work on so we must be even more careful about making assumptions. Consider the possibility that all the data fields are FK links to other tables for instance.

Nevertheless, we can no more assume that, than that the data fields pertain to standard data such as names or other basic data, so the Normalisation point is worth including.
Feb 7 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: shiyuan | last post by:
Dear Sir: We have created a table with a column of composite type. how can we insert values in this table. for exemple: create table aa (a int); create tabel bb (b aa); how to insert data ...
9
by: Hi5 | last post by:
Hi, Any Idea how, I can make an Insert statement to insert data into 6 different tables, that are all holding all data of my database? Is there any example? I would be grateful if you could...
1
by: Pratik Gupte | last post by:
I have created a database in .mdf format, but I am unable to insert data into its tables. Can anybody help how to insert data using ASP.Net 2.0 using SQL Server 2005 Express edition in windows...
4
by: shreedhan | last post by:
I have two tables table1 and table2 Table1 has a foreign key which references key of table2 Table2 also has a foreign key which references key of table1 Now when I try to insert into any of...
5
by: narendrareddy | last post by:
Hi , assume a flat file name emp.txt contains the following data 10000100001 narendranathreddy tallapireddy 01-01-2007 male 10000100002 ravindranathreddy tallapireddy 01-01-2008 male...
17
by: msmjsuarez | last post by:
Hello, I need help... How to automatically insert data to mysql database without submit button using php? Is there a way on this? thanks a lot.
2
by: msmjsuarez | last post by:
Hello. Is it possible to insert data to two tables at one time using one form only? I'm using php and mysql. Thanks advance.
2
by: shivasusan | last post by:
Hi! I have two tables in my database (userinfo, logininfo) - userinfo table has five fields (uname, pws, con_pws, squest, sans) - logininfo table has then six fields (fname,lname,dob,add1,...
3
by: southpawjoe | last post by:
Hi, I would like to insert data into two related tables in a SQL Server 2008 database. I created the following stored procedure but it has a problem. When I add a record, the State table gets...
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...
1
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.