1 00:00:01,410 --> 00:00:03,270 - [Instructor] For our first series of examples 2 00:00:03,270 --> 00:00:07,110 in this lesson, we'll be focusing on relational databases 3 00:00:07,110 --> 00:00:09,620 and the structured query language. 4 00:00:09,620 --> 00:00:12,230 So as you probably know a database is simply 5 00:00:12,230 --> 00:00:16,380 a collection of data and traditional relational database 6 00:00:16,380 --> 00:00:20,780 management systems focus on storing that data in tables 7 00:00:20,780 --> 00:00:22,990 and sometimes many tables 8 00:00:24,682 --> 00:00:25,850 that have relationships between them. 9 00:00:25,850 --> 00:00:29,090 We'll be focusing on using the Structured Query Language 10 00:00:29,090 --> 00:00:31,430 or sequel as many people referred to it 11 00:00:31,430 --> 00:00:34,200 some read it by the letters SQL 12 00:00:34,200 --> 00:00:38,000 and that is the pretty much universal language 13 00:00:38,000 --> 00:00:40,780 of relational database systems. 14 00:00:40,780 --> 00:00:44,060 We'll demonstrate some queries that extract data 15 00:00:44,060 --> 00:00:48,770 from a database and we'll also take a look at capabilities 16 00:00:48,770 --> 00:00:51,470 for inserting records into a database, 17 00:00:51,470 --> 00:00:54,950 updating records and deleting records as well. 18 00:00:54,950 --> 00:00:58,370 Now for the purpose of these examples we'll be focused 19 00:00:58,370 --> 00:01:01,830 on using the sequel light database management system, 20 00:01:01,830 --> 00:01:04,580 which comes bundled with Python, 21 00:01:04,580 --> 00:01:08,290 and as you'll see there's also a module built 22 00:01:08,290 --> 00:01:11,000 into the Python standard library 23 00:01:11,000 --> 00:01:13,373 for interacting with sequel light. 24 00:01:15,490 --> 00:01:17,800 Now when we're working with relational data, 25 00:01:17,800 --> 00:01:21,080 we're going to be using tables that consist 26 00:01:21,080 --> 00:01:22,690 of rows and columns, 27 00:01:22,690 --> 00:01:25,360 and the relational database itself is just 28 00:01:25,360 --> 00:01:28,610 a table based representation of data. 29 00:01:28,610 --> 00:01:32,010 So this is a simple employee table 30 00:01:32,010 --> 00:01:34,840 in which we have several rows of data, 31 00:01:34,840 --> 00:01:36,720 several columns of data, 32 00:01:36,720 --> 00:01:40,000 and specifically you notice that we marked 33 00:01:40,000 --> 00:01:43,810 the number column as a primary key. 34 00:01:43,810 --> 00:01:47,510 This is a value that helps uniquely identify 35 00:01:47,510 --> 00:01:50,053 each of the rows within a given table. 36 00:01:52,570 --> 00:01:56,860 Now every row describes one unique entity 37 00:01:56,860 --> 00:02:00,770 in the case of our employee table up above one employee 38 00:02:00,770 --> 00:02:02,900 and the columns within a given row 39 00:02:02,900 --> 00:02:06,500 are the individual pieces of data or attributes 40 00:02:06,500 --> 00:02:09,570 associated with that unique entity, 41 00:02:09,570 --> 00:02:11,870 and as I mentioned the primary key, 42 00:02:11,870 --> 00:02:15,320 is usually a column but it could also be a group of columns 43 00:02:15,320 --> 00:02:20,320 and that is used to uniquely identify every one of the rows. 44 00:02:20,510 --> 00:02:22,940 Now when you're working with those tables, 45 00:02:22,940 --> 00:02:24,810 one of the most common things you'll do 46 00:02:24,810 --> 00:02:27,970 is use sequel queries to grab subsets 47 00:02:27,970 --> 00:02:30,250 of the data in a given table. 48 00:02:30,250 --> 00:02:33,500 So this is a result of an example 49 00:02:33,500 --> 00:02:36,520 in which you select from that employee table, 50 00:02:36,520 --> 00:02:39,130 each department and its location, 51 00:02:39,130 --> 00:02:41,390 and here we happen to be presenting the data 52 00:02:41,390 --> 00:02:44,380 in increasing order by department number. 53 00:02:44,380 --> 00:02:47,430 So one of the things that we'll be able to do for example, 54 00:02:47,430 --> 00:02:51,020 is to sort the results that we are getting back 55 00:02:51,020 --> 00:02:53,880 when we query the database. 56 00:02:53,880 --> 00:02:57,720 Now as we work our way through this section 16_02 57 00:02:57,720 --> 00:03:00,960 and its subsections, again we'll be focused on using 58 00:03:00,960 --> 00:03:03,780 the sequel light database management system. 59 00:03:03,780 --> 00:03:08,650 It's an open source DBMS, and again included with Python, 60 00:03:08,650 --> 00:03:11,210 most of the popular database systems out there 61 00:03:11,210 --> 00:03:14,920 have Python support, so once you choose 62 00:03:14,920 --> 00:03:18,400 whichever database management system you want to use, 63 00:03:18,400 --> 00:03:22,311 you would simply take advantage of whatever 64 00:03:22,311 --> 00:03:24,630 Python module they provide 65 00:03:24,630 --> 00:03:27,483 for interacting with that database.