How to insert or update rows in one statement: Databases for Developers #17

  Рет қаралды 9,495

The Magic of SQL

The Magic of SQL

Күн бұрын

Sometimes when adding rows to your database need update-if-exists, insert-if-not-exists logic. Aka an upsert.
You could write this as separate update and insert statements. But there is an easier way:
Merge!
Watch this video for an overview of how merge works.
Further reading:
Merge documentation: docs.oracle.co...
Delete rows not in the source using merge: technology.ami...
Take the course: devgym.oracle....
Need help with SQL? Ask us over on AskTOM: asktom.oracle.com
Twitter: / chrisrsaxon
Daily SQL Twitter tips: / sqldaily
All Things SQL blog: blogs.oracle.c...
============================
The Magic of SQL with Chris Saxon
Copyright © 2015 Oracle and/or its affiliates. Oracle is a registered trademark of Oracle and/or its affiliates. All rights reserved. Other names may be registered trademarks of their respective owners. Oracle disclaims any warranties or representations as to the accuracy or completeness of this recording, demonstration, and/or written materials (the “Materials”). The Materials are provided “as is” without any warranty of any kind, either express or implied, including without limitation warranties or merchantability, fitness for a particular purpose, and non-infringement.

Пікірлер: 21
@staykings6943
@staykings6943 15 сағат бұрын
Thanks for this 💱
@bestjokesever212
@bestjokesever212 2 жыл бұрын
This is probably the best youtube channel to learn SQL. Hats off to you. Please keep uploading this kind of videos.
@TheMagicofSQL
@TheMagicofSQL 2 жыл бұрын
Thanks - you're welcome! Any particular topics you'd like to see covered?
@bestjokesever212
@bestjokesever212 2 жыл бұрын
@@TheMagicofSQL I would like to see more videos on best practices, pitfalls, common misconceptions, tips and tricks. In general anything that will help a person working with data.
@TheMagicofSQL
@TheMagicofSQL 2 жыл бұрын
Thanks for the suggestions - I'll bear these mind You might be interested in Ask TOM Office Hours. I've got many recordings that go deeper into specific topics - view these at asktom.oracle.com/pls/apex/f?p=100:570::::570::&cs=3VZVK8QMmqbvOYw3a1sJ6prq9ttSBgOFNRp03H72Gakn3zIK0ia2L36ZTxzapknIEUgCxwM50hH7wlvI14i1ONg
@vincentenrouelibre
@vincentenrouelibre 2 жыл бұрын
Thank you so much, this is a life-saver 🙏
@debpatro
@debpatro 5 жыл бұрын
Does the merge query works effectively while processing large volumes of data?
@TheMagicofSQL
@TheMagicofSQL 5 жыл бұрын
It only scans the rows in the source and target tables once. So generally it'll be at least as effective as any other solution And, as discussed in the video, it's often much faster than a correlated update.
@venkateshv-x2l
@venkateshv-x2l Жыл бұрын
will you suggest for single statement for insert and update using oracle ?
@TheMagicofSQL
@TheMagicofSQL Жыл бұрын
Merge as explained in this video
@TheNanamimijojo
@TheNanamimijojo 4 жыл бұрын
hi sir i have question i have two daya base have big data want to put data in data base 1 into data base 2 there are 20 table and the two data base have same keys and relation ship
@TheMagicofSQL
@TheMagicofSQL 4 жыл бұрын
I'm not sure what it is you're trying to do. Please make a complete example (create tables, inserts) and post it on asktom.oracle.com and we'll see what we can do to help
@mohamadrezamotaghi7427
@mohamadrezamotaghi7427 5 жыл бұрын
THAT WAS GREAT, THANKS
@TheMagicofSQL
@TheMagicofSQL 5 жыл бұрын
Thanks, glad you liked it :)
@JanaSainik_jsp
@JanaSainik_jsp 3 жыл бұрын
All of sudden performance decreased, we didn't change any code . Even DBA unable to trce the issue. Pls suggest cuases
@TheMagicofSQL
@TheMagicofSQL 3 жыл бұрын
There are a huge number of possible reasons; Jonathan Lewis has catalogued many at jonathanlewis.wordpress.com/2013/12/23/plan-changes/
@Pluto102
@Pluto102 6 жыл бұрын
Can you make few videos on MATCH RECOGNIZE
@TheMagicofSQL
@TheMagicofSQL 6 жыл бұрын
Patience! It's on my to-do list; it'll be a while before I can produce one
@rohitkumar-nk6sd
@rohitkumar-nk6sd 2 жыл бұрын
Hi iam getting error when iam running in postgresql what to do help me out
@TheMagicofSQL
@TheMagicofSQL 2 жыл бұрын
I specialize in Oracle Database; if you need help with PostgreSQL you'll need to find another forum. Note PostgreSQL doesn't support MERGE yet; if you're trying to do this you'll need to use another method to upsert the data.
@dn9416
@dn9416 6 жыл бұрын
Nice
How do SQL queries return correct results? Databases for Developers #18
9:11
didn't manage to catch the ball #tiktok
00:19
Анастасия Тарасова
Рет қаралды 31 МЛН
Миллионер | 2 - серия
16:04
Million Show
Рет қаралды 1,2 МЛН
Стойкость Фёдора поразила всех!
00:58
МИНУС БАЛЛ
Рет қаралды 7 МЛН
Viral Video of a Man's Crazy Job Interview
16:02
Darryl Vega TV
Рет қаралды 1,3 МЛН
SQL UPDATE Statement |¦| SQL Tutorial |¦| SQL for Beginners
8:03
How to Read an Execution Plan: Databases for Developers: Performance #1
9:34
SQL - Merge
10:35
James Oliver
Рет қаралды 35 М.
How I use SQL as a Data Analyst
15:30
Luke Barousse
Рет қаралды 833 М.
How to Create Database Indexes: Databases for Developers: Performance #4
12:47