1/9
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
what is SQL used for?
used to retrieve data from relational databases using certain commands
how to write a SELECT command?
SELECT {field you want to show}
SELECT * {selects all fields in a table}
this retrieves a record. other commands can then be carried out on the record without affecting the whole database
how to use FROM in a SELECT command?
SELECT {field you want to show} FROM {table you want to choose}
example - SELECT firstName FROM student
this identifies the table where the data come from
how to use WHERE in a SELECT command?
SELECT {field you want to show} FROM {table you want to choose} WHERE {search criteria}
search criteria could be Gender = 'Male' or Age = 11
this limits retrieval of those record that match a set of criteria
how to use INSERT command?
INSERT INTO {table} VALUES {values that need to be entered as a record}
this is used to insert new records in a table
how to use UPDATE command?
UPDATE {table} SET {field = 'what you want to set it to'} WHERE {primary key condition}
example of primary key condition -> WHERE StudentID = 2
this changes the data in one or more records in a table
how to use DELETE command?
DELETE FROM {table} WHERE {primary key condition}
example of primary key condition -> WHERE StudentID = 2
how to use ORDER BY command?
SELECT {fields you want to show} FROM {table you want to order} WHERE {condition} ORDER BY {field} ASC/DESC or a field
this is used to sort the result set in ascending or descending order
how to state a join in a relational database?
{table1.field/primary key} = {table2.field/foreign key}
example -> student.studentID = volunteer.studentID
how to structure a long answer SQL query in exams?
SELECT (fields separated by commas)
FROM (tables separated by commas)
WHERE (relational database join and or condition)
ORDER BY (fields) ASC/DESC