SQL Basics
Structured Query Language (SQL)
- SQL: a language used for interacting with Relational Database Management System (RDBMS)
1. You can use SQL to get the RDBMS to do things for you
- Create, retrieve, update & delete data
- Create & manage databases
- Design & create database tables
- Perform administration tasks (security, user management, import/export, etc)
2. SQL implementations vary between systems
- Not all RDBMS’ follow the SQL standard to a ‘T' (Postgres, MySQL, Oracle, Microsoft SQL Server)
- The concepts are the same, but the implementation may vary
3. SQL is actually a hybrid language, it’s basically 4 types of language in one
- Data Query Language (DQL)
· Used to query the database for information
· Get information that is already stored there
- Data Definition Language (DDL)
· Used for defining database schemas
*Schemas: Overall layout of the database.
ex > what columns those tables are going to have and the data types that those columns are going to be able to store
- Data Control Language (DCL)
· Used for controlling access to the data in the database
· User & permissions management
- Data Manipulation Language (DML)
· Used for inserting, updating, and deleting data from the database
Queries
- Query: a set of instructions given to the RDBMS, written in SQL that tell the RDBMS what information you want it to retrieve for you
· TONS of data in a DB
· Often hidden in a complex schema
· Goal is to only get the data you need
SELECT employee.name, employee.age
FROM employee
WHERE employee.salary > 3000;
MySQL Mac Installation
1. Click https://dev.mysql.com/downloads/mysql/
2. Download ‘DMG Archive’ > Click ‘No thanks, just start my download’ which is in the bottom of the next page
3. Username: root, password: (set your own password) > follow the download instruction on Mac
4. Open ‘terminal’ application
5. Type mysql -u root -p
6. Type password
7. Type create database giraffe;
*giraffe is the name of the database: you can use another name
8. Click https://popsql.com
9. Sign up with google account and download the app
*PopSQL connect MySQL database server that we have set up
10. Go to the link: app.popsql.com
11. Click ‘PopSQL’ > Click ‘Manage Connection’
12. Connection name: mysql / Hostname: localhost / Database: giraffe / username: (your username), password: (your password)