473,480 Members | 2,157 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

selective insert and update

43 New Member
hi
how can i insert a record in a table if it doesnt exist already and update the record otherwise ie if record exists then it must be updated and if not exist then inserted.

is it possible through one query... For example :
TableOne
ColumnOne|ColumnTwo|....
jhon |123455|....

now a record jhon,10000 comes since jhon already exist so it must be updated
if steve,45 comes it must be inserted

Any suggestions..... Thanks in advance...
Mar 20 '08 #1
6 2880
debasisdas
8,127 Recognized Expert Expert
You can use SQL Server 2008's new MERGE statement if using that version .That allows you to insert, update, or delete data based on certain join conditions in the same statement.
Mar 20 '08 #2
bravo
43 New Member
Thanks for ur reply DADA,

but i am using mysql 4.1 is it possible in that .. or i have to first run a query to check the existence of the record then update or insert.. that will be tooo time consuming but i dont have any choice .. can u suggest me a way...
Mar 20 '08 #3
ronverdonk
4,258 Recognized Expert Specialist
You can use SQL Server 2008's new MERGE statement if using that version .That allows you to insert, update, or delete data based on certain join conditions in the same statement.
Are you advertising for Microsoft software in the FREE MySQL forum? Shame on you.

Ronald
Mar 20 '08 #4
debasisdas
8,127 Recognized Expert Expert
Oh...

I am really sorry. I mistook that for SQL Server forum question.
Mar 20 '08 #5
ronverdonk
4,258 Recognized Expert Specialist
Thanks for ur reply DADA,

but i am using mysql 4.1 is it possible in that .. or i have to first run a query to check the existence of the record then update or insert.. that will be tooo time consuming but i dont have any choice .. can u suggest me a way...
You can do it in one query with REPLACE, BUT only and only when the old row in the table has the same value as a new row for a PRIMARY KEY or a UNIQUE index, . See the appropriate chapter in the MySQL documentation for your MySQL version HERE

Ronald
Mar 20 '08 #6
debasisdas
8,127 Recognized Expert Expert
Are you advertising for Microsoft software in the FREE MySQL forum? Shame on you.

Ronald
No no no ........

Not at all . I actually mistook this as a SQL Server question in a hurry.

I am again sorry for that .
Mar 20 '08 #7

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

Similar topics

0
322
by: Mike Connor | last post by:
I am having trouble getting Conditional Folder creation & File insertion to work using VS .Net in a Deployment Project for a C# app. I am displaying a generic Textbox Dialog under the User...
14
4267
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
16969
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
3838
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...
16
2175
by: Lyle Fairfield | last post by:
There is an MS-SQL table named Bugs_Comments_and_Suggestions. There is a form named Bugs_Comments_and_Suggestions. To allow John Doe to use this form, we GRANT him LOGIN and ACCESS permissions...
3
3421
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
18304
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...
4
8782
by: mmanojkumar | last post by:
Sir, I have a recordset "ADODC_path.recordset" which takes input from two tables When the field values are put into the textboxes and then edited and updated back into the tables, using the...
3
1404
by: rpk740 | last post by:
Not sure if the subject makes sense, but it was the best I could think of. We have a Table that contains a schedule. The schedule has certain pieces of information that are required to be updated...
0
6920
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6760
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7022
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5365
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4501
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3013
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3004
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.