Updating 2 Tables at once

M

MRW

Quick question for anybody who can help:

I have two tables:

tblUsers
--------
UserID
Name

tblPhones
---------
PhoneID
UserID
PhoneNumber

If I'm collecting the name and the phone numbers (can be multiple
numbers) in one form, what's the best way of placing it in the
database? The question revolves around the UserID and making sure the
tblPhones.UserID = tblUsers.UserID

Thanks for any help!
 
M

Mark Rae

Quick question for anybody who can help:

I have two tables:

tblUsers
--------
UserID
Name

tblPhones
---------
PhoneID
UserID
PhoneNumber

If I'm collecting the name and the phone numbers (can be multiple
numbers) in one form, what's the best way of placing it in the
database? The question revolves around the UserID and making sure the
tblPhones.UserID = tblUsers.UserID

Thanks for any help!

Is the UserID already known, or are you adding one record to tblUsers and
one or more to tblPhones? If the former, is tblUsers.UserID an identity
field? If so, you can retrieve the identity by SELECT @@IDENTIY or SELECT
SCOPE_IDENTITY. Then you can use that to pump the records into tblPhones.
 
S

Sarat Pediredla

Based on that fact that you mention that the UserID is an auto
incremented field, I am assuming this is an IDENTITY and the SELECT
@@IDENTITY in your SQL should do it for you.
 
M

MRW

Thanks for the feedback!

I'll be honest. I'm not familiar with the @@IDENTITY. Can you give a
quick example on how it is used (VB)?

Thank you for the help!
 
M

Mark Rae

Great! Thanks a lot!

Sarat's comment about Google is very relevant, though... you really could
have found this out for yourself in a matter of seconds...
 
M

MRW

I've been on Google searching for things for hours. I did not find
anything that would have led me to @@IDENTITY. So when he told me, I
simply asked if he had a quick example on how to use it while I've got
him.
 
J

JT

To Mark & Sarat:

We all appreciate your help. And I try to help when I can. Isn't that
why this group is here? If we are just going to tell people to go look
on Google, why does this group exist? I'm sure you're both very
helpful and generous in most cases. If you were a guru sitting on a
mountaintop and someone climbed up to ask a question, wouldn't you
think they were an idiot if they climbed back down and then had to
climb back up to ask a follow-up question instead of asking while they
had your attention?

Now blithering idiots should go study before peppering you with inane
questions, but that's a different situation (IMHO).

We all have bad days...

BTW, I benefitted from your answers, too.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top