SQL Basics Flashcards
Creating Tables
CREATE TABLE Students(name VARCHAR(20), identification INT)
Constraints
CONSTRAINT PRIMARY KEY (identification)
Dropping Tables
DROP TABLE Students;
Inserting into tables
INSERT INTO Students(name, identification) VALUES (‘Jake’, 204902);
Selecting Values
SELECT * FROM Students;
Modifying Tables
ALTER TABLE Students ADD email VARCHAR(100);
ALTER TABLE Students MODIFY email VARCHAR(200);
Deleting Values
DELETE FROM Students WHERE name=’Jake’
Updating Values
UPDATE Students SET identification=20139 WHERE name=’Jake’
Conditions
- NOT -> use everything except what is specified
- BETWEEN -> between integers (10 and 20 etc)
- LIKE -> for string matching
Projection
Allows you to choose what to select (SELECT * ,SELECT Events etc. You could have SELECT Grades, Name, aka multiple).
Distinct
Removes duplicate rows (SELECT DISTINCT.
Renaming
Allows you to rename attributes (SELECT Event AS Activity, SELECT first_name, family_name AS Surname)
New Columns
Using math and AS to create new columns (SELECT Price * Number AS Total_cost).
Cross Product
In a way, its joining tables (SELECT first_name, grade FROM Students, Results).
Natural Join
Another way of doing it (SELECT * FROM Employees NATURAL JOIN Transactions)