Structured query language (SQL) Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is SQL used for?

A

creating, maintaining and accessing databases

it allows users to search for records that contain a particular item or items of data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

data

A

units of information

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

database

A

data store designed in an organised way, making it easier to search for the information you need

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

records

A

all of the data related to one entity in a database

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is data in a database stored as?

A

records

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are records stored in?

A

files

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

attribute

A

a single database component

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

List 6 SQL commands

A
SELECT
FROM
WHERE
LIKE
AND
OR
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How are databases formatted/what do they look like?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

WHERE keyword

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

formatting an SQL command (5)

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

SELECT keyword

A

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;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

wildcards

A
  • 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

LIKE command

A

finds matches for an incomplete word:

SELECT * FROM Students WHERE TutorGroup LIKE “%X”;

the = command can be used to find complete words

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

AND and OR commands (Boolean operators)

A

can also be used to retrieve data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

FROM command

A

specifies the name of the database to search

17
Q

Details of the employees of a multinational company are stored in a database table named ‘Employees’ using these fields:

  • EmployeeNo
  • FirstName
  • Surname
  • DOB
  • Country
  • JobFunction

Write the SQL commands that would return the following records:

a) All employees showing only the Surname and Country fields. [2]
b) Employees with the word ‘computer’ in their job titles. All fields should be displayed. [2]

A

a) SELECT Surname, Country FROM Employees;

b) SELECT * FROM Employees
WHERE JobFunction LIKE “%computer%”;

18
Q

Details of a school’s students are stored in a database named ‘Students’ containing the following fields:

  • FirstName
  • Surname
  • DOB
  • Gender
  • Address1
  • Address2
  • Town
  • PostCode
  • SchoolYear
  • TutorGroup

Write the SQL commands that would return the following records:

a) all students showing the FirstName, Surname and PostCode fields
b) Students who are in the year 10 tutor group named East showing all the fields. [5]

A

a) SELECT FirstName, Surname, Postcode FROM Students;

b) SELECT * FROM Students
WHERE TutorGroup = “EAST” AND SchoolYear = 10;