SQL - Basics Flashcards
SELECT
extracts data from a database
UPDATE
updates data in a database
DELETE
deletes data from a database
INSERT INTO
Inserts new data into a database
CREATE DATABASE
creates a new database
ALTER DATABASE
modifies a database
CREATE TABLE
creates a new table
ALTER TABLE
modifies a table
DROP TABLE
deletes a table
CREATE INDEX
creates an index (search key)
DROP INDEX
deletes an index
SELECT * FROM Customers;
Selects all the records in “Customers”
* = select all
SELECT DISTINCT Country FROM Customers;
Selects only different “countries” from customers.
Note: Without the “DISTINCT” it would have duplicates.
The distinct removes duplicates and only shows a list of different ones.
SELECT Count(*) AS DistinctNumber
FROM (SELECT DISTINCT Country FROM Customers);
Selects the number of different countries. The “AS” Sets a name for the column. As there is two select features, you need the other one in brackets. “FROM” needs to be before the start of the bracket so we know where we are getting the info from.
Note: If there’s multiple Commands, the others need to be in brackets.
SELECT * FROM Customers
WHERE country = ‘Mexico’;