1 00:00:00,780 --> 00:00:02,730 ‫Transaction, what is a transaction? 2 00:00:03,270 --> 00:00:08,660 ‫We hear this a lot in databases, a transaction, it's nothing but a bunch of queries. 3 00:00:08,830 --> 00:00:10,880 ‫OK, it's a collection of queries. 4 00:00:10,920 --> 00:00:13,860 ‫So it's a one or more queries game. 5 00:00:14,430 --> 00:00:21,360 ‫And that property of these queries or they are you one unit of work? 6 00:00:21,750 --> 00:00:26,160 ‫An example would be if you want to deposit an account. 7 00:00:26,310 --> 00:00:26,870 ‫Right. 8 00:00:26,910 --> 00:00:33,360 ‫And some cash into an account that is actually a select statement followed by a statement followed by 9 00:00:33,360 --> 00:00:36,410 ‫another update, something like we now we're going to show in the second round. 10 00:00:36,780 --> 00:00:39,560 ‫But each one of those is a query. 11 00:00:39,870 --> 00:00:47,250 ‫The three of them can form a transaction and you define what a transaction begin and where transaction 12 00:00:47,250 --> 00:00:47,660 ‫end. 13 00:00:47,880 --> 00:00:53,940 ‫And we also there is another semantic attached to a transaction like a commit. 14 00:00:53,940 --> 00:00:56,160 ‫Hey, I am happy with my changes. 15 00:00:56,160 --> 00:01:00,750 ‫Go persist them, commit that sort of commitment, roll back. 16 00:01:00,750 --> 00:01:03,000 ‫You know what I think something went wrong. 17 00:01:03,240 --> 00:01:05,400 ‫Roll back, abort, abort, abort. 18 00:01:05,430 --> 00:01:10,790 ‫So that's another two piece of concept then attach by a transaction. 19 00:01:10,950 --> 00:01:11,760 ‫We know that. 20 00:01:11,790 --> 00:01:13,380 ‫Let's just jump into example. 21 00:01:13,710 --> 00:01:14,460 ‫A transaction. 22 00:01:14,700 --> 00:01:19,890 ‫I have an account here with a beautiful table just to feel because that's all where you need obviously 23 00:01:19,890 --> 00:01:20,940 ‫for in a bank or I have to. 24 00:01:20,960 --> 00:01:22,830 ‫Still feels like you don't need a name. 25 00:01:22,830 --> 00:01:23,880 ‫You don't need anything else. 26 00:01:24,240 --> 00:01:25,320 ‫No data, no. 27 00:01:25,620 --> 00:01:26,400 ‫Just do field. 28 00:01:26,850 --> 00:01:28,950 ‫So there's I got the idea there is a balance. 29 00:01:29,190 --> 00:01:33,690 ‫This guy has a thousand dollars, guys added to five, five hundred. 30 00:01:34,350 --> 00:01:38,790 ‫And the transaction is send hundred dollars from account one to account to us. 31 00:01:38,800 --> 00:01:40,140 ‫So what do we need to do first. 32 00:01:40,920 --> 00:01:43,250 ‫Does account one even have a hundred dollar. 33 00:01:43,410 --> 00:01:44,130 ‫I don't know. 34 00:01:44,130 --> 00:01:50,940 ‫So I need to check to us, we're going to begin the transaction, get a select let's check the balance. 35 00:01:51,660 --> 00:01:53,520 ‫Do you have one hundred dollars that. 36 00:01:53,850 --> 00:01:54,240 ‫Yes. 37 00:01:54,240 --> 00:01:55,800 ‫Your balance is a balance. 38 00:01:55,830 --> 00:01:57,630 ‫Go to the 100 yard sir. 39 00:01:58,290 --> 00:01:59,450 ‫It is greater than a hundred. 40 00:01:59,550 --> 00:01:59,940 ‫All right. 41 00:02:00,000 --> 00:02:02,820 ‫Let's debit that hundred minus hundred. 42 00:02:03,250 --> 00:02:04,800 ‫OK, so now it's nine hundred. 43 00:02:05,130 --> 00:02:09,180 ‫OK, but that's not committed is just the math, right? 44 00:02:09,600 --> 00:02:10,900 ‫It's just touched. 45 00:02:10,920 --> 00:02:12,870 ‫It's a dirty change game. 46 00:02:13,350 --> 00:02:17,080 ‫And then I'm going to add another hundred to the second account. 47 00:02:17,250 --> 00:02:19,050 ‫I'm going to commit my changes. 48 00:02:19,050 --> 00:02:19,830 ‫Turning green. 49 00:02:19,830 --> 00:02:21,560 ‫I mean, this is like it's persisted. 50 00:02:21,570 --> 00:02:22,170 ‫All good. 51 00:02:22,200 --> 00:02:23,670 ‫We're happy and that's it. 52 00:02:23,940 --> 00:02:26,340 ‫OK, so that's essentially what a transaction is. 53 00:02:26,340 --> 00:02:31,500 ‫It's a unit of work, but it consists of multiple queries, one or more as a transaction.