SQL Basic Flashcards
SQL and MySQL
SQL Structured Query Language
MySQL Database management sysytem-DBMS, other are PostgreSQL, SQLite, Oracle, There are slight differences in the syntax. Implement SQL standard
changing/selecting database
Use Database_name
to check what db i am using
Select Database_Name()
To drop a database:
DROP DATABASE <database-name>;</database-name>
To use a database:
USE <database-name>;</database-name>
To list available databases:
show databases;
The general command for creating a database:
CREATE DATABASE <database_name>;</database_name>
CREATE DATABASE soap_store;
2 main data types
numeric and string
show tables;
show columns from Table1;
DESC Table1;
Insert a cat into a table
INSERT INTO cats (name, age)
VALUES (‘Blue Steele’, 5);
Primary key
means unique,
auto-increment
cat_id INT PRIMARY KEY
at the begging or
PRIMARY KEY (cat_id)
at the end
Update example
UPDATE cats SET breed=’Shorthair’ WHERE breed=’Tabby’;
using SET and where
What to use before Deleting/Updating
Select before UPDATE/ DELETE!
String functions
- concat
- substring
- replace
- reverse
- char_length
- upper&lower
using select
SELECT CONCAT(author_fname,’ ‘, author_lname) AS author_name FROM books;
SELECT SUBSTRING(‘Hello World’, 1, 4);
Refining selections
distinc- only unique values -> Select Distinct
SELECT DISTINCT author_lname FROM books;