By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,386 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

INSERT or UPDATE

P: n/a
Hi All,
I have the a table with 2 fields: uid, date.
When the user does some activity I log his uid and the date, the
problem I have is that the table is not prepoulated with all uid's so
sometimes I need to INSERT and other times I need to UPDATE (if that
uid was already logged). Checking first with SELECT to see if the uid
exist is the obvious thing but I wonder is there a more effective way?

App is ASP.NET 2.0 in VB

Thanks
PxP

Jun 4 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"pxpilot" <px*****@gmail.comwrote in message
news:11**********************@m36g2000hse.googlegr oups.com...
but I wonder is there a more effective way?
I don't believe so...

So long as the id is (part of) the primary key, the first check should be
virtually instantaneous...
--
http://www.markrae.net

Jun 4 '07 #2

P: n/a
On Jun 4, 7:53 am, "Mark Rae" <m...@markNOSPAMrae.netwrote:
"pxpilot" <pxpi...@gmail.comwrote in message

news:11**********************@m36g2000hse.googlegr oups.com...
but I wonder is there a more effective way?

I don't believe so...

So long as the id is (part of) the primary key, the first check should be
virtually instantaneous...

--http://www.markrae.net
Is there some sort of user registration process? If so, modify it to
insert a new record into your table. Then the registration process can
always do the insert, and the other code can always do updates.

Jun 4 '07 #3

P: n/a
Hello pxpilot,

It depends on your DB, some of them support MERGE (Oracle for example), which
call either insert or update.
for SQL server you need to implement your SP, there is no merge afaik
---
WBR, Michael Nemtsev [.NET/C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

pHi All,
pI have the a table with 2 fields: uid, date.
pWhen the user does some activity I log his uid and the date, the
pproblem I have is that the table is not prepoulated with all uid's so
psometimes I need to INSERT and other times I need to UPDATE (if that
puid was already logged). Checking first with SELECT to see if the uid
pexist is the obvious thing but I wonder is there a more effective
pway?
pApp is ASP.NET 2.0 in VB
p>
pThanks
pPxP
Jun 4 '07 #4

P: n/a
Hi All,
I have the a table with 2 fields: uid, date.
When the user does some activity I log his uid and the date, the
problem I have is that the table is not prepoulated with all uid's so
sometimes I need to INSERT and other times I need to UPDATE (if that
uid was already logged). Checking first with SELECT to see if the uid
exist is the obvious thing but I wonder is there a more effective way?
App is ASP.NET 2.0 in VB

Thanks
PxP
You could start with the UPDATE and check how many rows were updated.
If 0, then use the INSERT.
This way you execute 1 or 2 statements, instead of always 2 for the
SELECT-route.

Hans Kesting
Jun 4 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.