SQL Query Flashcards

1
Q

Give the SQL instruction to: Create a table called students
(StudentNumber as primary key, forename, surname, and date of birth)

A

CREATE TABLE students
(
StudentNumber INT PRIMARY KEY,
forename TEXT,
surname TEXT,
DateOfBirth DATE
)

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

SQL: What is the keyword for deleting a database/table?

A

DROP …

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

What are the SQL data types

A

CHAR(size) // → fixed length string
VARCHAR(size) // → string (with a maximum length)
‘TEXT’ // → string
ENUM // → string object that has to be chosen from a list of possible values
BOOL / BOOLEAN
INT(size) // → size is the number of digits
FLOAT(size,d) // → size is the number of digits , with d digits after the decimal point
DATE
TIME
DATETIME

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

Give the SQL WHERE command for: all strings beginning with ‘bor’

A

LIKE ‘bor%’

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

Give the SQL WHERE command for: any strings at least five characters long

A

LIKE ‘_____%’

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

Give the SQL WHERE command for: a studentID between 10 an d100 numbers

A

… WHERE StudentID BETWEEN 10 AND 100

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

Give the SQL command for: ordering results by surname

A

ORDER BY surname

ORDER BY surname ASC

ORDER BY surname DESC

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

Give the SQL command for: Inserting data into the student table
Assume it’s of the form: Students(StudentID, Forename, Surname, House)

A

INSERT INTO students VALUES(‘’,’’,’’,’’), (‘’,’’,’’,’‘)…

INSERT INTO students (surname , forename) VALUES (__…
//if you can’t remember what order you’re supposed to do it in)

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

Give the SQL command for: update a forename to ‘Harry’ where…:

A

UPDATE students SET forename = ‘Harry’ WHERE…

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

Give the SQL command for: Delete a record from the students table

A

DELETE FROM students WHERE …

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

Give the SQL command for: Selecting from two tables

A

SELECT table1.attributeX , table2.attributeY
FROM table1 , table2
WHERE table1.primarykey = table2.foreignkey
AND …

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