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

INSERT or UPDATE

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
4 1195
"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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: shottarum | last post by:
I currently have 2 tables as follows: CREATE TABLE . ( mhan8 int, mhac02 varchar(5), mhmot varchar(5), mhupmj int )
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...
3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
20
by: Mark Harrison | last post by:
So I have some data that I want to put into a table. If the row already exists (as defined by the primary key), I would like to update the row. Otherwise, I would like to insert the row. I've...
3
by: V T | last post by:
Hello all, SQL Server 2000 documentation http://www.microsoft.com/technet/prodtechnol/sql/2000/reskit/part10/c3761.mspx states that if view is using "NOT NULL" columns of a base table, then...
1
by: abhi81 | last post by:
Hello All, I have a table on which I have created a insert,Update and a Delete trigger. All these triggers write a entry to another audit table with the unique key for each table and the timestamp....
4
by: =?Utf-8?B?UmljaA==?= | last post by:
On a form - I have a datagridview which is docked to the entire form. The datagridview allows users to Delete and/or Add Rows. On the Form_Load event I Fill the datagridview source table with a...
0
by: magnolia | last post by:
i created a trigger that will record the changes made to a table .everything works fine except the insert query.whenerever i try to insert a record it fires insert and update triger at the same time...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.