1 00:00:00,410 --> 00:00:03,970 Now that we've got a table, let's start inserting some data. 2 00:00:03,970 --> 00:00:08,820 Just like how we created the table, we can insert data right from the command line. 3 00:00:08,820 --> 00:00:12,510 Let's try inserting a 2003 Ford Taurus as our first row. 4 00:00:13,560 --> 00:00:18,606 Let's type INSERT INTO CARS, And 5 00:00:18,606 --> 00:00:24,696 for the values, we can give an ID of one for 6 00:00:24,696 --> 00:00:29,568 the first row, and we need Ford, 7 00:00:29,568 --> 00:00:33,225 Taurus, and 2003. 8 00:00:33,225 --> 00:00:35,652 And don't forget the semi colon. 9 00:00:35,652 --> 00:00:37,260 Then we can hit Enter to run it. 10 00:00:38,580 --> 00:00:42,340 And since we don't see an error message, that means that it worked. 11 00:00:42,340 --> 00:00:45,316 And if we want to make sure it worked, we can use the Select statement. 12 00:00:45,316 --> 00:00:52,660 Let's try selecting * from the CARS table to see what we've got. 13 00:00:54,500 --> 00:00:56,390 Perfect, there's our car. 14 00:00:57,590 --> 00:01:02,040 Though you don't always have to write your SQL statements at the command line. 15 00:01:02,040 --> 00:01:05,930 If you happen to have a lot of statements to run or just want to write SQL using 16 00:01:05,930 --> 00:01:10,860 a more modern editor, then you can always put your SQL in a separate file and 17 00:01:10,860 --> 00:01:15,820 use the .read command to execute the SQL statements contained in that file. 18 00:01:15,820 --> 00:01:20,385 In fact, if we scroll up a little bit, 19 00:01:20,385 --> 00:01:25,394 we can see the .read command right here. 20 00:01:25,394 --> 00:01:26,454 Okay, go ahead and 21 00:01:26,454 --> 00:01:30,242 download the new cars that txt file from the Teacher's Note below. 22 00:01:30,242 --> 00:01:32,188 Once you got the file, 23 00:01:32,188 --> 00:01:39,121 let's put it on our database practice folder and see what we've got. 24 00:01:39,121 --> 00:01:41,977 Looks like a few insert statements. 25 00:01:41,977 --> 00:01:45,970 But if you wanted, you could include any kind of SQL here. 26 00:01:45,970 --> 00:01:48,980 You could create tables, delete tables, whatever you want. 27 00:01:50,100 --> 00:01:50,905 Back in the terminal, 28 00:01:50,905 --> 00:01:56,998 let's try to run those insert statements by using the read command. 29 00:01:56,998 --> 00:02:02,283 Let's type .read and then the file 30 00:02:02,283 --> 00:02:07,070 name which is new_cars .txt. 31 00:02:07,070 --> 00:02:10,710 Then hit enter and it looks like it worked. 32 00:02:10,710 --> 00:02:14,380 Then let's use the up arrow to choose the select statement again and 33 00:02:14,380 --> 00:02:15,480 see what we've got in the table. 34 00:02:17,250 --> 00:02:21,080 Awesome, it ran the insert statements and added the new cars. 35 00:02:22,090 --> 00:02:25,402 Though it's a little difficult to see what's going on here, everything's all 36 00:02:25,402 --> 00:02:28,485 scrunched together and it would be nice if we could see the column headers. 37 00:02:30,312 --> 00:02:35,070 Luckily, SQL Lite gives us tools to solve each of these problems. 38 00:02:35,070 --> 00:02:39,786 To turn headers on, we just need to use the .headers command and set it to on. 39 00:02:39,786 --> 00:02:45,730 Let's type .headers on. 40 00:02:45,730 --> 00:02:47,600 Hit Enter, and 41 00:02:47,600 --> 00:02:50,600 then run our Select statement again using the up arrow to choose it. 42 00:02:52,610 --> 00:02:54,420 And there we go, we've got some headers. 43 00:02:56,050 --> 00:02:59,910 Now to fix the column spacing, we can use the .mode command and 44 00:02:59,910 --> 00:03:01,160 set the mode to column. 45 00:03:03,200 --> 00:03:10,558 So let's type .mode column, then run that command, arrow up to our select statement. 46 00:03:11,990 --> 00:03:13,620 And success! 47 00:03:13,620 --> 00:03:17,225 We can finally read the results of our query without needing to squint. 48 00:03:18,265 --> 00:03:22,265 There's so much you can do with SQL, even right from the command line. 49 00:03:22,265 --> 00:03:25,595 So the next time you need to set up a database, give SQLite a try.