SQL Flashcards
How do you use the SELECT statement to extract a collection of fields from a table?
SELECT [field1, field2, etc.]
FROM [table]
WHERE [search criteria boolean statement]
ORDER [order to be displayed in, desc or asc]
How do you use the SELECT statement to extract a collection of fields from more than one table?
SELECT [record1.field, record2.field1, record2.field2]
FROM record1, record2
WHERE [search criteria boolean statement]
ORDER [order to be displayed in, desc or asc]
How do you use JOIN to combine rows from two or more tables based on a common field between them?
SELECT [record1.field, record2.field1, record2.field2]
FROM record1
JOIN record2
ON [e.g. record1.personID = record2.personID]
WHERE [search criteria]
How do you add a column/field to a table?
ALTER TABLE [table name]
ADD [field name] [data type e.g. VARCHAR(10)]
How do you modify a column/field in a table?
ALTER TABLE [table name]
MODIFY COLUMN [field name] [change e.g. VARCHAR(20)]
How do you delete a column/field from a table?
ALTER TABLE [table name]
DROP COLUMN [column name]
How do you modify a specific record in a table?
UPDATE [table name]
SET [column1 = value1, column2 = value2, etc]
WHERE columnX = valueX