Databases and SQL Flashcards
Give the format for creating a table.
CREATE TABLE (name)
(
Attribute1, INT(numDigits), PRIMARY KEY
Attribute2,VARCHAR(numCharacters)/TEXT, FOREIGN KEY
Attribute3, DATE
)
Give the format for adding values into a table.
INSERT INTO (name)
VALUES (‘value1’,’value2’,’value3’),
(‘value4’,’value5’,’value6’)
Give the format for updating values in a table.
UPDATE (name)
SET (Attribute2) = ‘value3’
WHERE (Attribute1) = ‘value1’
Give the format for deleting values in a table.
DELETE FROM (name)
WHERE (Attribute1) = ‘value1’
Give the format for selecting items/values.
SELECT *(everything) / (Attribute1), (Attribute2)
FROM (name)
WHERE (Attribute1) = ‘value1’ / > (value2)
ORDER BY (Attribute3) DESC # default is ascending
Give the line for selecting the first value from the first entity found.
SELECT DISTINCT (Attribute1)
What is the format for DATE?
YYYY-MM-DD
What is the format for TIME?
HH:MM:SS
What is the definition of a primary key?
An attribute/field which uniquely identifies a record.
What is the definition of a foreign key?
A attribute/field in one table which refers to the primary key in another table.