[Script Info] Title: [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: 0,0:00:00.00,0:00:07.94,Default,,0000,0000,0000,, Dialogue: 0,0:00:07.94,0:00:09.32,Default,,0000,0000,0000,,PROFESSOR: In this\Nsection, we're Dialogue: 0,0:00:09.32,0:00:13.05,Default,,0000,0000,0000,,going to be talking about\Nupdating data, deleting data, Dialogue: 0,0:00:13.05,0:00:14.96,Default,,0000,0000,0000,,and we're going to\Nlearn a few new commands Dialogue: 0,0:00:14.96,0:00:16.94,Default,,0000,0000,0000,,and functions within Neo4j. Dialogue: 0,0:00:16.94,0:00:18.56,Default,,0000,0000,0000,,In this first section,\Nwe'll be talking Dialogue: 0,0:00:18.56,0:00:22.58,Default,,0000,0000,0000,,about updating existing\Nnodes and relationships, Dialogue: 0,0:00:22.58,0:00:26.90,Default,,0000,0000,0000,,using new keywords to find\Ndata, deleting nodes, detaching Dialogue: 0,0:00:26.90,0:00:30.95,Default,,0000,0000,0000,,relationships, and detaching\Nand deleting nodes. Dialogue: 0,0:00:30.95,0:00:33.05,Default,,0000,0000,0000,,In this first\Nvideo, we'll go over Dialogue: 0,0:00:33.05,0:00:36.59,Default,,0000,0000,0000,,some of the capabilities of the\NMERGE statement in preparation Dialogue: 0,0:00:36.59,0:00:38.09,Default,,0000,0000,0000,,of the rest of the video. Dialogue: 0,0:00:38.09,0:00:40.88,Default,,0000,0000,0000,,And then we'll look at\Nthe commands of MERGE, Dialogue: 0,0:00:40.88,0:00:44.49,Default,,0000,0000,0000,,the conditions that happen\Nwhen you create a new node, Dialogue: 0,0:00:44.49,0:00:46.73,Default,,0000,0000,0000,,as well as the conditions\Nthat happen when Dialogue: 0,0:00:46.73,0:00:48.80,Default,,0000,0000,0000,,you match an existing node. Dialogue: 0,0:00:48.80,0:00:52.61,Default,,0000,0000,0000,,We'll also use MERGE\Nwhere we could use MATCH Dialogue: 0,0:00:52.61,0:00:56.06,Default,,0000,0000,0000,,and SET to change attributes. Dialogue: 0,0:00:56.06,0:00:58.70,Default,,0000,0000,0000,,To review, we have\Na basic data model Dialogue: 0,0:00:58.70,0:01:01.23,Default,,0000,0000,0000,,set up with actors and movies. Dialogue: 0,0:01:01.23,0:01:05.61,Default,,0000,0000,0000,,Our goal was to solve the six\Ndegrees of Kevin Bacon problem. Dialogue: 0,0:01:05.61,0:01:10.38,Default,,0000,0000,0000,,This first MERGE statement\Nwill find an actor with the ID1 Dialogue: 0,0:01:10.38,0:01:11.94,Default,,0000,0000,0000,,and will show its information. Dialogue: 0,0:01:11.94,0:01:15.30,Default,,0000,0000,0000,,In the Neo4j web\Nbrowser, we can type Dialogue: 0,0:01:15.30,0:01:23.52,Default,,0000,0000,0000,,merge parentheses lowercase A\Nas in Alias, actor as the label. Dialogue: 0,0:01:23.52,0:01:30.51,Default,,0000,0000,0000,,We can specify the ID of 1 to\Nfilter, and we can return a. Dialogue: 0,0:01:30.51,0:01:32.55,Default,,0000,0000,0000,,When we execute\Nthis statement, we Dialogue: 0,0:01:32.55,0:01:38.01,Default,,0000,0000,0000,,should receive one node\Nrepresenting Kevin Bacon. Dialogue: 0,0:01:38.01,0:01:42.07,Default,,0000,0000,0000,,We can look in the rows, the\Ntexts to show more raw results. Dialogue: 0,0:01:42.07,0:01:46.23,Default,,0000,0000,0000,,We can show all the attributes\Nfor this Kevin Bacon actor. Dialogue: 0,0:01:46.23,0:01:50.52,Default,,0000,0000,0000,,We can also use MERGE\Nto create new nodes. Dialogue: 0,0:01:50.52,0:01:54.00,Default,,0000,0000,0000,,Here we'll create a new\Nactor node with the ID of 99 Dialogue: 0,0:01:54.00,0:01:54.96,Default,,0000,0000,0000,,and we'll return it. Dialogue: 0,0:01:54.96,0:02:01.73,Default,,0000,0000,0000,,Again, we'll type merge, a,\Nan Alias actor, ID of 99, Dialogue: 0,0:02:01.73,0:02:03.47,Default,,0000,0000,0000,,and will return a. Dialogue: 0,0:02:03.47,0:02:07.56,Default,,0000,0000,0000,,We know this data doesn't\Nexist since we only set up-- Dialogue: 0,0:02:07.56,0:02:11.00,Default,,0000,0000,0000,,we know this data doesn't exist\Nbecause we only set up actors 1 Dialogue: 0,0:02:11.00,0:02:12.41,Default,,0000,0000,0000,,through 7 or so. Dialogue: 0,0:02:12.41,0:02:15.98,Default,,0000,0000,0000,,So when we execute this,\Nit will create a new node Dialogue: 0,0:02:15.98,0:02:19.04,Default,,0000,0000,0000,,with no attributes,\Noops, because we only Dialogue: 0,0:02:19.04,0:02:23.60,Default,,0000,0000,0000,,supplied the ID parameter\Nor the ID attribute Dialogue: 0,0:02:23.60,0:02:25.11,Default,,0000,0000,0000,,in the MERGE statement. Dialogue: 0,0:02:25.11,0:02:28.85,Default,,0000,0000,0000,,What we should have done\Nto create a new actor Dialogue: 0,0:02:28.85,0:02:32.03,Default,,0000,0000,0000,,node with more attributes\Nis specify those attributes Dialogue: 0,0:02:32.03,0:02:33.50,Default,,0000,0000,0000,,within the MERGE statement. Dialogue: 0,0:02:33.50,0:02:36.80,Default,,0000,0000,0000,,Here we're going to make\Nan actor with the ID of 99 Dialogue: 0,0:02:36.80,0:02:40.28,Default,,0000,0000,0000,,and the name of George George. Dialogue: 0,0:02:40.28,0:02:42.81,Default,,0000,0000,0000,,When we execute that\NCipher statement, Dialogue: 0,0:02:42.81,0:02:48.41,Default,,0000,0000,0000,,we'll see the new actor\Ncreated with the ID of 99. Dialogue: 0,0:02:48.41,0:02:53.57,Default,,0000,0000,0000,,Now the problem is we ran the\Nmerge twice with an ID of 99. Dialogue: 0,0:02:53.57,0:02:56.31,Default,,0000,0000,0000,,So if we run it again\Nwithout the name, Dialogue: 0,0:02:56.31,0:03:00.39,Default,,0000,0000,0000,,this should match on all\Nnodes with the ID of 99, Dialogue: 0,0:03:00.39,0:03:06.33,Default,,0000,0000,0000,,and in this case, we will\Nget our two actor nodes. Dialogue: 0,0:03:06.33,0:03:10.17,Default,,0000,0000,0000,,The MERGE statement can also\Nact like an insert or update Dialogue: 0,0:03:10.17,0:03:13.74,Default,,0000,0000,0000,,statement or construct within\Ntraditional database systems. Dialogue: 0,0:03:13.74,0:03:16.20,Default,,0000,0000,0000,,Using the MERGE\Nstatement, you can Dialogue: 0,0:03:16.20,0:03:18.54,Default,,0000,0000,0000,,create a condition\Ncalled ON CREATE Dialogue: 0,0:03:18.54,0:03:22.23,Default,,0000,0000,0000,,and you can execute or\Nupdate specific values. Dialogue: 0,0:03:22.23,0:03:25.14,Default,,0000,0000,0000,,You can also set the\Ncondition for ON MATCH where Dialogue: 0,0:03:25.14,0:03:26.59,Default,,0000,0000,0000,,you can do something else. Dialogue: 0,0:03:26.59,0:03:31.35,Default,,0000,0000,0000,,In this case, we'll create a\Nnew actor with the ID of 98. Dialogue: 0,0:03:31.35,0:03:34.74,Default,,0000,0000,0000,,When it's created, we'll\Nset the name to Mark Hamill Dialogue: 0,0:03:34.74,0:03:36.55,Default,,0000,0000,0000,,and we'll add a counter field. Dialogue: 0,0:03:36.55,0:03:40.32,Default,,0000,0000,0000,,We haven't done this yet, but\Nwe'll add a counter field of 0. Dialogue: 0,0:03:40.32,0:03:46.53,Default,,0000,0000,0000,,If we rerun this MERGE statement\Nand the condition of ID 99 Dialogue: 0,0:03:46.53,0:03:51.24,Default,,0000,0000,0000,,is already met, we'll execute\Nthe statements ON MATCH section Dialogue: 0,0:03:51.24,0:03:54.82,Default,,0000,0000,0000,,where we'll set the counter\Nto the counter plus 1, Dialogue: 0,0:03:54.82,0:03:57.71,Default,,0000,0000,0000,,effectively incrementing\Nthe counter every time Dialogue: 0,0:03:57.71,0:03:59.33,Default,,0000,0000,0000,,we merge on this node. Dialogue: 0,0:03:59.33,0:04:00.62,Default,,0000,0000,0000,,Let's try it out. Dialogue: 0,0:04:00.62,0:04:03.38,Default,,0000,0000,0000,,You'll see here we can\Ntype this MERGE statement, Dialogue: 0,0:04:03.38,0:04:05.30,Default,,0000,0000,0000,,merge, actor ID 98. Dialogue: 0,0:04:05.30,0:04:11.27,Default,,0000,0000,0000,,ON CREATE, we'll set the name to\NMark Hamill with a counter of 0. Dialogue: 0,0:04:11.27,0:04:16.28,Default,,0000,0000,0000,,ON MATCH, we'll set the\Ncounter to counter plus 1 Dialogue: 0,0:04:16.28,0:04:18.09,Default,,0000,0000,0000,,and we'll return the actor node. Dialogue: 0,0:04:18.09,0:04:21.38,Default,,0000,0000,0000,,Here we'll execute it and\Nwe should see our new node. Dialogue: 0,0:04:21.38,0:04:26.33,Default,,0000,0000,0000,,If we look at the raw results\Nwe'll see a counter of 0. Dialogue: 0,0:04:26.33,0:04:27.30,Default,,0000,0000,0000,,So using the browser. Dialogue: 0,0:04:27.30,0:04:30.11,Default,,0000,0000,0000,,We can click on the\NCipher statement again. Dialogue: 0,0:04:30.11,0:04:32.96,Default,,0000,0000,0000,,Press it again, our\Ncounter will increment. Dialogue: 0,0:04:32.96,0:04:36.23,Default,,0000,0000,0000,,And every time we\Nexecute this since we're Dialogue: 0,0:04:36.23,0:04:40.61,Default,,0000,0000,0000,,matching on the ID of 98,\Nour counter increments. Dialogue: 0,0:04:40.61,0:04:43.37,Default,,0000,0000,0000,,So this shows the\Ntwo conditions we Dialogue: 0,0:04:43.37,0:04:48.31,Default,,0000,0000,0000,,have used in the MERGE statement\NON CREATE and ON MATCH. Dialogue: 0,0:04:48.31,0:04:57.00,Default,,0000,0000,0000,,