SQL Flashcards
All 13 cards in this deck
In SQL, what does
SELECT *do?Retrieves all fields from the records that match the query.
In SQL, what does the
FROMcommand specify?Which table the data is retrieved from.
In SQL, what does the
WHEREcommand do?e.g.
WHERE Year = 11Filters the records so only those meeting the condition are returned — only records whose Year is 11.
In SQL, how do you select more than one field?
e.g. the
NameandYearfieldsList the field names after
SELECT, separated by commas:SELECT Name, Year(notAND).In an SQL
WHEREclause, what is the difference betweenANDandOR?ANDmeans all the conditions must be true;ORmeans at least one condition must be true.In SQL, what does
ORDER BYdo?e.g.
ORDER BY Surname ASCSorts the results by the named field.
ASCgives ascending order (A to Z, smallest first);DESCgives descending order (Z to A, largest first).In an SQL query that uses two tables, how are the tables linked in the
WHEREclause?e.g. tables
MemberandAward, both with aMemberIDfieldWith a condition that matches the foreign key to the primary key, naming each table:
WHERE Member.MemberID = Award.MemberID.In SQL, how must text values be written in a condition?
e.g. finding the city Leeds
Inside quotation marks:
WHERE City = 'Leeds'. Numbers are written without quotes, e.g.WHERE Age = 14.Which SQL command adds a new record to a table?
INSERT INTO, followed by the table name, the field names in brackets, thenVALUESwith the data in brackets in the same order:INSERT INTO Pet (PetID, Name) VALUES (7, 'Rex')Which SQL command changes data in records that already exist?
UPDATE, withSETgiving the new values andWHEREchoosing the records:UPDATE Pet SET Weight = 4.2 WHERE PetID = 7Which SQL command removes records from a table?
DELETE FROM, withWHEREchoosing the records to remove:DELETE FROM Pet WHERE PetID = 7What happens if an SQL
UPDATEorDELETEcommand has noWHEREclause?It acts on every record in the table: every record is changed, or every record is deleted.
In SQL
UPDATEandDELETEcommands, why is the primary key often used in theWHEREclause?Its value is unique, so the condition picks out exactly one record. A condition on a non-unique field, such as a name, could change or delete other records too.