473,608 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
+ 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|Colum nTwo|....
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 2886
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 Interface menu and have 3 checkboxs enabled (1-3) using default name of CHECKBOXB1, 2 & 3. Under the File System menu I would like to selective create 3 folder & insert files into the folder depending on the state of a checkbox - 1 folder per checkbox....
14
4282
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 salvage the records from the many table and without going into detail, one of the reasons I can't do the opposite as there are records in the ONE table that I need to keep even if they don't have any child records in the MANY table. Below I created...
16
17000
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 must be UPDATED, if not, they must be INSERTED. Logically then, I would like to SELECT * FROM <TABLE> WHERE ....<Values entered here>, and then IF FOUND UPDATE <TABLE> SET .... <Values entered here> ELSE INSERT INTO <TABLE> VALUES <Values...
16
3865
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 table, or perhaps bytes, being updated where the engine just decides, screw it, i'll just make a new one. surfed this group and google, but couldn't find anything. the context: we have some java folk who like to parametize/
16
2196
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 to the db and SELECT permissions on the stored procedure which is the record source for the BOUND form. To allow John Doe to "UPDATE, INSERT, DELETE" using the BOUND form, we GRANT John Doe "UPDATE, INSERT, DELETE" permissions on the table,
3
3437
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 the necessary records in it when testing it. I get the error "No value given for one or more required parameters." when I try to update the database. Can you tell me what am I doing wrong?
20
18333
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 been doing something like delete from foo where name = 'xx'; insert into foo values('xx',1,2,...);
4
8791
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 following codes, everything works fine. "select * from path,Station where path.StationCode=Station.StationCode and path.traincode=" & Text2.Text Two tables Station(fields: StationCode and StationName) and Path(fields: StationCode ,TrainCode...
3
1410
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 by certain members of the organization, specifically Shift, Start Date, and Line. Each record also has a column for the customer that it is for. I have built a cross reference table that contains the customer and the NT User that is responsible...
0
8003
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8152
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6817
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3962
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4025
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2474
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 we have to send another system
1
1598
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1331
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.