Structured query language (SQL) Flashcards
What is SQL used for?
creating, maintaining and accessing databases
it allows users to search for records that contain a particular item or items of data
data
units of information
database
data store designed in an organised way, making it easier to search for the information you need
records
all of the data related to one entity in a database
What is data in a database stored as?
records
What are records stored in?
files
attribute
a single database component
List 6 SQL commands
SELECT FROM WHERE LIKE AND OR
How are databases formatted/what do they look like?
a table, for example:
StudentNo FirstName Surname DOB TutorGroup
001123 Fred Smith 28/01 10X
001142 Angela Smith 13/10 10Y
002567 Mary Green 15/2 10X
WHERE keyword
used for searching
e.g.
SELECT FirstName, Surname (the fields to display)
FROM Students (the name of the database)
WHERE TutorGroup = “10X” AND DOB > 31/1/2001; (the search criteria)
formatting an SQL command (5)
- write commands on separate lines to make them easier to understand
- every command (not line) ends with a ;
- commands are not case sensitive
- fields are separated with a comma
- the fields may also be shown in quotations
SELECT keyword
used to display records
e.g.
SELECT * FROM Students; (Displays all the records and shows all the fields, the * symbol means ‘show all fields’)
SELECT FirstName, Surname FROM Students;
wildcards
- the % symbol is used as a substitute for one or many characters
- the * symbol is used to represent ‘all fields’
WHERE TutorGroup LIKE “%X”;
…returns all fields with a tutor group ending in an X, and any characters before that
LIKE command
finds matches for an incomplete word:
SELECT * FROM Students WHERE TutorGroup LIKE “%X”;
the = command can be used to find complete words
AND and OR commands (Boolean operators)
can also be used to retrieve data