How do you select data in SQL?
Using
SELECT field FROM table WHERE condition
How do you use SQL to find an item that starts with, ends with, or contains a specific character
[WHERE condition] becomes:
WHERE condition LIKE character% when searching for items that start with the character
WHERE condition LIKE %character when searching for items that end with with the character
WHERE condition LIKE %character% when searching for items that contain the character
How do you select the items in all fields of a record?
Using SELECT *
How do you implement multiple conditions?
Using AND and/or OR
How do you add a record into a database using SQL?
By inserting the record’s data using:
INSERT INTO table (field1, field2, field3)
VALUES(value1, value2, value3)
E.g. INSERT INTO world(name, capital, population)
VALUES(“Oz”, “Emerald City”, 1000000)
How do you delete a record/records from a table?
Using:
DELETE FROM table
WHERE condition
How do you join tables?
Using:
SELECT table.field
FROM table
JOIN table2,
ON table1.field = table2.field
WHERE condition
The specified field is the foreign key.
E.g.
SELECT Student.Surname, Tutor_Group.Tutor room
FROM Student
JOIN Tutor_Group
ON Student.Tutor Group = Tutor_Group.Tutor Group
WHERE Student.Tutor Group = “10B”
How do you delete a table?
Using:
DROP TABLE table
Describe referential integrity
When relationships between databases are consistent, such that each foreign key links to an existing primary key.
Why is referential integrity desirable?
It ensures that information is not removed if it is required elsewhere in a linked database, in order to prevent the occurrence of missing data.
How can referential integrity be broken?
If a primary key is deleted or updated or if a foreign key is no longer valid.