CS50x 2024 - Lecture 7 - SQL
HTML-код
- Опубликовано: 6 июн 2024
- ***
This is CS50, Harvard University's introduction to the intellectual enterprises of computer science and the art of programming.
***
TABLE OF CONTENTS
00:00:00 - Introduction
00:01:01 - Flat-file Databases
00:33:00 - Relational Databases
00:57:02 - Halloween Costume Contest
00:58:31 - Shows
00:59:30 - Schema
01:13:29 - Data Types and Constraints
01:15:04 - Primary and Foreign Keys
01:17:43 - Querying
01:47:24 - Indexes
01:55:44 - Python and SQL
02:00:30 - Race Conditions
02:06:47 - SQL injection attacks
***
HOW TO SUBSCRIBE
ruclips.net/user/subscription_c...
HOW TO TAKE CS50
edX: cs50.edx.org/
Harvard Extension School: cs50.harvard.edu/extension
Harvard Summer School: cs50.harvard.edu/summer
OpenCourseWare: cs50.harvard.edu/x
HOW TO JOIN CS50 COMMUNITIES
Discord: / discord
Ed: cs50.harvard.edu/x/ed
Facebook Group: / cs50
Faceboook Page: / cs50
GitHub: github.com/cs50
Gitter: gitter.im/cs50/x
Instagram: / cs50
LinkedIn Group: / 7437240
LinkedIn Page: / cs50
Medium: / cs50
Quora: www.quora.com/topic/CS50
Reddit: / cs50
Slack: cs50.edx.org/slack
Snapchat: / cs50
SoundCloud: / cs50
Stack Exchange: cs50.stackexchange.com/
TikTok: / cs50
Twitter: / cs50
RUclips: / cs50
HOW TO FOLLOW DAVID J. MALAN
Facebook: / dmalan
GitHub: github.com/dmalan
Instagram: / davidjmalan
LinkedIn: / malan
Quora: www.quora.com/profile/David-J...
TikTok: / davidjmalan
Twitter: / davidjmalan
***
CS50 SHOP
cs50.harvardshop.com/
***
LICENSE
CC BY-NC-SA 4.0
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License
creativecommons.org/licenses/...
David J. Malan
cs.harvard.edu/malan
malan@harvard.edu
01:02 Introducing the need for different tools in software programming and the introduction of SQL.
03:11 Google Forms data integrates with Google Sheets for analysis.
07:16 CSV files use quotes for strings with commas to avoid confusion
09:28 Using 'with' in Python to automatically close files.
13:36 Using dictionary to access data instead of numeric indices
15:43 Iterating over a file row by row and incrementing counters based on the content
19:37 Using dictionaries to count occurrences of values in a loop.
21:44 Using dictionaries to track and print values
25:44 Python makes sorting easier with built-in functions and rich libraries
27:46 Python's Counter class simplifies counting and sorting
31:54 SQL allows for interactive and efficient data analysis
33:54 SQL is a declarative language for describing data retrieval and analysis.
37:33 Loading data into SQLite using the command line
39:27 Overview of 'schema' command and selecting columns from a database
43:33 SQL provides various functions like count and distinct to retrieve specific data from tables.
45:29 SQLite distills things into the essence and is widely used.
49:29 Changing the query to get a top list and using aliases
51:29 Adding data to a table using SQL.
55:25 Updating and modifying data in SQL tables.
57:19 Dealing with real-world data sets from large databases
1:00:56 Discussing the design of the spreadsheet implementation.
1:02:39 Eliminating redundancy in data storage
1:06:43 Exploring SQL database normalization
1:08:43 Working with IMDb data and converting to SQLite format
1:12:38 Understanding data types and primary/foreign keys in SQL.
1:14:26 Database design allows for null constraints, unique values, and relationships between tables.
1:18:34 Using SQL to filter and select specific data from multiple tables.
1:20:36 Using SQL to retrieve shows with ratings 6.0 and above.
1:24:21 Joining tables and filtering data based on conditions.
1:26:25 Using SQL and joins to retrieve specific data from tables.
1:30:25 Using SQL to query and reference data in tables.
1:32:23 Using SQL to compose smaller ideas into larger queries for data retrieval.
1:36:11 Using a third table in a many-to-many relationship requires additional steps to retrieve data.
1:38:20 Retrieving person IDs associated with a specific show ID using nested queries
1:42:17 Executing joins with multiple tables in SQL
1:44:36 Different ways to join tables in SQL
1:48:16 Creating indexes in SQL can significantly improve query performance.
1:50:12 Optimizing database performance using indexing
1:54:09 Indexes drastically improve query performance
1:56:19 Resetting and importing data in SQL using SQLite3 and Python
2:00:26 Managing large databases in SQL
2:02:29 Race conditions in large systems
2:06:05 Use transactions to avoid race conditions in SQL.
2:08:09 Single quotes are important in SQLite for strings and comments
2:11:49 Using a library like CS50 handles escaping of user input
Where can i get the Google forms data bro?
This lecture is worth the same as an entire semester of two subjects in my university course
Actually it's completely worthless. You can just have a chatgpt with things you don't understand. I've seen this guy before. He's using way too many words to explain the basics. He's just wasting everyones time trying to promote how prestegious universities are, but everyone is capable of learning. Some people, those who go to a university, need a little pushing. As if it's a mental illness.
@@denysolleik9896 Not everyone is as smart as you, brother. I myself am not a fan of learning through ChatGPT or any other AI because it easier for me to learn things through a person's explanation.
Just beautiful. This was a significant improvement over last year's lecture and I really liked it. Thank you Prof. Malan!
Great lecture as always. Thanks CS50 and Prof. David Malan for offering this course to everyone free of cost.
Thank you, dr. Malan
People like you are really inspirational for CS world.
this professor is a teaching machine, way to go!!!!
Awesome video! I'm picking up SQL for the first time, and using it as part of my PhD in humanities, and this was perfect to get started, thank you!
Thank you Dr. Malan! A great lecture! It is very noble of you to make such knowledge readily accessible and explained in a captivating way.
Great lecture Dr. Malan! Shout out to the supporting team behind too for breaking the educational barriers
I love how he teach..
I love how he explain..
Man.. Wish the world have a people like him on every life-aspect
Like when i was learning to drive 😔
the best intro of CS50
Equal equals equal in sequel is my new favorite tongue twister
Learning SQL is like learning PLC programming. The syntax, theory, workflow, framework... are pretty straightforward. The clusterfeck comes when you start working and realizing that other people's system and setup are ridiculous (and now you are tasked with maintaining or scaling it).
Especially when you get real-world experience with legacy SQL systems. Databases are a f*cking nightmare to work through. It's all archaic non-sense.
Yeet.
You should see the DB2 Database at my work. It's a foreign language with SQL sprinkled in.
I am not even programming, but I like to get inspired by his energy and knowledge. Thanks for the upload and thanks to David J. Malan.
fantastic lecture as always, thank you!
One of the best teachers EVER!!
As always best lecture 💚
Thank You, David for everything. I really liked the Milk analogy.
❤❤ Great lecture as always.
i went to an SQL course at Oracle 25 years ago... the basics have not changed but this is clearly and well explained and once you master it, it is so much better than python for large data queries . CS50 is really the best.
I don't think SQL and Python are even comparable.
Python evidently has larger parameters for its usage,. However, in the context of data analysis, they can be comparable.
@@charliebitmyfinger7124
@@charliebitmyfinger7124 bros out here comparing general purpose full fledged programming language to a query language lmao
@@SnPnibba I think HTML is the best programming language!
great lecture ;
So thorough!
This is so nice for beginners
Honestly wish the first part of the lecture opening csv files was included in the last video. Really struggled with this in pset DNA
true
@@sefonefinpsefnpefn4191 just drag the csv file from your local computer and drop it in the web terminal
Same lol
For DNA I just skipped the CSV module and did it with string methods. In particular .split(",")
Amazing professor! I was looking for vídeo tutorial to recommend to a friend. This one is perfect.
I got a question, I wonder if you can help, I notice his terminal is so clean when running his programs, do you have an idea how he set it up like that ?
@@ad5772 Hi! I never used, but I believe he is executing commands on the command line window on VS Code (press CTRL + J). I usually use Microsoft Studio Managment Studio to access usually SQL Server. He is using SQLite.
Ask ChatGPT: "How to execute sql commands on sqlite through vs code terminal window".
Here is the answer that it respond it:
```
You can use an extension to open, view, and query SQLite database files directly in **Visual Studio Code**. Here's how:
1. **Install the Extension**:
- Click on **Extensions** in the left sidebar (you can also open the Extensions menu by pressing **Ctrl + Shift + X** on Windows or Linux, or **Command + Shift + X** on macOS).
- Type **SQLite** and install the extension by **alexcvzz**.
- Click on the **Install** button.
2. **Open an SQLite File**:
- Once you've installed the extension, you can open an SQLite file by:
- Right-clicking on the file in **Explorer**.
- Clicking on **Open Database**.
- The database will appear as a collapsed menu in the **Explorer** tab.
- Click on **SQLite Explorer** to expand the database.
- You can then click on a specific table and view its data or run a query.
3. **Running Queries**:
- To run a query, create a **.sql** file (e.g., **001.sql**) and type your query.
- For example, to select the first 10 rows from a table called **albums**, use:
```sql
SELECT * FROM albums LIMIT 10;
```
- To run the query:
- Press **Ctrl + Shift + P** on Windows and Linux (or **Command + Shift + P** on macOS).
- Type **SQLite run query** and select **SQLite: Run Query**.
- A new tab with the query results will open.
4. **Closing the Database**:
- When you're done working with the database, you can close it by:
- Pressing **Ctrl + Shift + P** on Windows and Linux (or **Command + Shift + P** on macOS).
- Typing **SQLite run query** and clicking on **SQLite: Close Database**.
Remember to expand the **SQLite Explorer** menu in the left sidebar after opening the database. Happy querying! 😊
For more details, you can refer to [this article](bobbyhadz.com/blog/vscode-view-query-sqlite).¹
Origem: conversa com o Bing, 09/05/2024
(1) How to open, view and query SQLite in VS Code | bobbyhadz. bobbyhadz.com/blog/vscode-view-query-sqlite.
(2) Transact-SQL with Visual Studio Code. code.visualstudio.com/docs/languages/tsql.
(3) How to run SQL query in visual Studio Code - Stack Overflow. stackoverflow.com/questions/72743136/how-to-run-sql-query-in-visual-studio-code.
```
An operating systems course by CS50 would be awesome
Learning from a Harvard Teacher from a brazilian favela for free.
Otimo irmao! Boa sorte pelo futuro! Segue assim :-)
Niiiice! 🙌
This is so awesome to hear.
I've been listening to him for free on Apple podcast since 2009 🙏
This is even before he started doing free lectures for everyone and even you could download the videos off the Apple podcast because it was only for Harvard students at that time
Now it's for everyone 🎉
lol same!
Vamo que vamo irmão 🤙
The opening music is awesome! Came for the class but stayed to listen to the opening music on loop!
Your priority = zero
Haha so true! You go become a tech tycoon!
reminded me of the start of a James Bond film
There's a whole new intro now!!
getting the information from the first part of the lecture would be super useful for the DNA task 😄
fr
you mean the problem from week 6?
@@farhanarahman9375yes
Exactly what I said 😭😭
Carter covers that on week's 6 section. Don't skip them! The sections from each week are super useful.
Thank you sir
thank you so much for this lecture, it was useful 🎯
That great!
GOAT ACTIVITIES
What would be the easiest way to view a relational view (as per in the video with the connected boxes) of the schema for shows.db? Could I export .schema's output into some sort of previewer?
edit: The term I was looking for is 'entity-relationship diagram'. As a manual workaround and some help from docs, I converted the sql to postgresSQL and used the dbizzy extention for vscode. It is a bit basic and doesn't show the one-to-one, one-to-many etc symbols, but it's a start.
NGL, the intro reminds me of GOT intro. EPIC.
Where can i find the data you use in the starting of the video?
1:16:33 I think he meant to say "primary key"
I'm grateful that I can understand English, as it allows me to learn from some of the world's leading professors.
我好喜歡他在講解 join 語法時,從長到短來介紹三種語法篇幅
1:42:17 Executing joins with multiple tables in SQL
1:44:36 Different ways to join tables in SQL
DAVID
Incredible eloquence at such talking speed ?
Without data there is no need for CS!
we need some videos for networking
47:53 "Equal equals equality in the world of 'Sequal'." 😂
Where can i get Show.db file?
Guys, if your terminal left aligns the output (unlike in the video), type in sqlite3 prompt: .mode table
how did he make his terminal so clean when he run his programs. I have vs code but I have literally failed to setup such an environment. Please be kind I am old
Wait everything getting uploaded all at once? Nice
1:44:24 stopped, indexes, rare condn., sql injections
what is the logic behind row 1, why all the entries has come in answer?, this is column value right
1:38:44 Batman swoops in
oh david mentioned the bobby table :) at the end
my favorite joke related to SQL and database
XKCD 327
Little Bobby TABLE
I'm a noob in SQL but why isn't my sqlite3 interface as neat as this interface with ASCII art? I downloaded it from the original website and I'm using it from Windows cmd. Is this a different version or from a different source? Mine doesn't even display the headers
Best to use cs50.dev ! Or on Windows, you can run `sqlite3 -table` !
@@davidjmalan OMG didn't expect Dr. Malan to reply to this! I thought that maybe others watching would reply. Thank you David! It works 🥰🥰🥰
A simple solution is to set your mode to table by using the following command `.mode table`
Hi Team, Can anyone teach about ETL concepts and how it works in real time project.
Describing joins as glue should result in the wrong mental model though. The use case Joins have been invented for is a glue-use-case, but it's a quite specific edge case. In actuality, joins are combinatoric operations, so you'd start with explaining cross joins first. All other joins are essentially cross joins within a domain (specified by keys with ON/USING) where you chuck out NULLs selectively depending on the kind of join (e.g. right-side NULLs in LEFT JOIN). Understanding the combinatorics nature of joins is so essential, especially when debugging and a key we thought was unique is not actually unique.
It would be great, if you could upload the favorites.csv file to the Lecture Notes!
Done!
im trying to find this file
Hello, would love to know the music composer's name
how can I get the shows.db file?
hy atvedx how ro i choose language
1:46:13
Show 62614:Zeg 'ns Aaa 😂 That's an old Dutch serie which my parents always watches
That's great!
what does code means in terminal when $ code favourites.csv is given in command line??
Code opens your file in the code editor
1:31:29
genre to show should be many to many as a genre can have multiple shows
One question: at 2:06:24 Does python automatically insert the missing semi-colons at the end of sql commands?
and also, I guess there shouldn't be semi-colon after db.execute() command as python doesn't need ( ; )
If they all teached like that I could get behind 100k degrees
i wonder wh y there are only 2 comments in such a informative video?
Because the matrix has attacked the minds of youth and made them into TIkTOK mind consuming dancing and shit videos and spending their life as a second class citizen as said by Top G !
@@thestraightpath2249Or most people just don't know about this because Harvard doesn't advertise these videos. What makes more sense a psyop like mk ultra or poor advertisement.
maybe because it was uploaded today?
@@thestraightpath2249 Or maybe most people just watch through CS50 Video Player? That makes more sense then the matrix. I don't see much reason for people to go here anyways other than for timestamps.
Still waiting for the updates on EdX😭
5-6 months SQL course in college < CS50 2 hours SQL Lecture
18:26
Tough crowd
아따 이집 맛집이네.... 잘가르치네
Yes indeed.. This restaurant is delicious
which year's recording is it ?
It says in the title 2024
Fall 2023
@@PabitraPadhy Must've missed Halloween 2024
Porfavor Inclui disponibilize Legendas em português Brasil
Pode fazer voce mesmo e manda pra eles :-)
I'm getting this error: cs50 has no SQL attribute. Can someone help me
Are you using cs50.dev or some other programming environment? Do email a screenshot, too, to sysadmins@cs50.harvard.edu!
@davidjmalan already fixed, thanks for being in touch. The error was because I named the file as cs50.py I renamed it and worked 👍
The first 30 minutes would have been helpful for the last problem set dna
Hi
first 30 minutes would of be nice to have it before past week 6 problem set...XDD
This year's SQL lecture is a lot easier to follow, which is convenient since I was halfway through the old one when it uploaded. I'm not sure about the new introduction though, the music choice is a little strange, I miss the old one
Yeah, the same thing happened to me. I was watching the old one on SQL when the new set of lectures was uploaded. And I agree with you on both of your points!
43:00
ayyyye im done
I know this already. But I still feel that I don't known anything. I am under valuing myself...please help sql interview seems very daunting
Yes, you are undervaluing yourself! Everyone feels like this with new material at some point. Just go back, watch it again, make some notes. Practice what he’a doing while you’re watching in the code editor they provide for free. You can also search out YT videos on the subject too. But don’t worry, we all feel like this at some point, it’s normal.
33:02
Hey
sequel
1 like = one minute of cs50
Aguante Messi y Argentina!
1like = 5pushups + 45min workout in 2024
comment = 10?
Do the pushups please
345 push ups hey
record and upload video of you doing the pushups
Like = 20pushup & squat 🙂
why didnt anybody laugh at the ending comic. i thought it was pretty funny😭🤣
23:12
Who else is watching Catweazle?
English?
1 like = 100 pushups in 2099😂
worst way to learn SQL
what would be the best way ?
50:00