Selecting and Retrieving Data with SQL Flashcards
What is SQL?
The standard computer language of database management systems
SQL for Data Science Week 1
How does SQL differ from other computer languages?
SQL is a descriptive and non-procedural language. You cannot write complete applications with SQL
SQL for Data Science Week 1
What three things is SQL used for?
- Read/retrieve data
- Write data
- Update data
SQL for Data Science Week 1
Examples of professions that use SQL
- Backend Developer
- QA Engineer
- DBA
- Data Analyst
- System Admin
- Data Architect
- ETL Developer
- Systems Engineer
- Data Scientist
SQL for Data Science Week 1
Compare and contrast roles of database administrator and data scientist
DBA
1. Manages entire database
2. Gives permissions to users
3. Determines who has access to what data
4. Manages and creates tables
5. Uses SQL to query and retrieve data
Data Scientist
1. End user of a database
2. Primarily use SQL to query and retrieve data
3. May create their own table or test environment
3. Combine multiple data sources together
4. Write complex queries for analysis
SQL for Data Science Week 1
Explain the importance of knowing which SQL syntax you’re using in a given database
Think of SQL as the interpreter between you and the database. There are slight syntax differences amongst systems. You must know the proper syntax to use to “talk” to the database.
SQL for Data Science Week 1
How do you limit the number of records returned?
SELECT columns you want
FROM table
LIMIT number of records
Just writing along sentence so it will left justify
SQL for Data Science Week 1
What is the different syntax amongst SQLite, Oracle and DB2 for limiting records?
SQLite
SELECT columns you want
FROM table
LIMIT n
Oracle
SELECT columns you want
FROM table
WHERE ROWNUM <=n
DB2
SELECT columns you want
FROM table
FETCH FIRST n ROWS ONLY
n=number of rows
SQL for Data Science Week 1
Why use comments?
- To reference when looking at code you have not reviewed in a while
- To comment out a section of code you no longer want/need to use but aren’t ready to delete
- To troubleshoot queries systematically
- To make your code easier to share
SQL for Data Science Week 1
How do you comment sql code?
- –Two dashes comments out a single line
- /* at the beginning of the section and */ at the end of the section comments out a section of sql
Don’t overdo comments. Add them where your sql doesn’t follow the normal flow. For example, you don’t need to explain what the select does and then what the from does and then what the group by does. These are self explanatory for those that use sql.
SQL for Data Science Week 1