SQL Query Flashcards
Give the SQL instruction to: Create a table called students
(StudentNumber as primary key, forename, surname, and date of birth)
CREATE TABLE students
(
StudentNumber INT PRIMARY KEY,
forename TEXT,
surname TEXT,
DateOfBirth DATE
)
SQL: What is the keyword for deleting a database/table?
DROP …
What are the SQL data types
CHAR(size)
// → fixed length stringVARCHAR(size)
// → string (with a maximum length)
‘TEXT’ // → stringENUM
// → string object that has to be chosen from a list of possible valuesBOOL / BOOLEAN
INT(size)
// → size is the number of digitsFLOAT(size,d)
// → size is the number of digits , with d digits after the decimal pointDATE
TIME
DATETIME
Give the SQL WHERE command for: all strings beginning with ‘bor’
LIKE ‘bor%’
Give the SQL WHERE command for: any strings at least five characters long
LIKE ‘_____%’
Give the SQL WHERE command for: a studentID between 10 an d100 numbers
… WHERE StudentID BETWEEN 10 AND 100
Give the SQL command for: ordering results by surname
ORDER BY surname
ORDER BY surname ASC
ORDER BY surname DESC
Give the SQL command for: Inserting data into the student table
Assume it’s of the form: Students(StudentID, Forename, Surname, House)
INSERT INTO students VALUES(‘’,’’,’’,’’), (‘’,’’,’’,’‘)…
INSERT INTO students (surname , forename) VALUES (__…
//if you can’t remember what order you’re supposed to do it in)
Give the SQL command for: update a forename to ‘Harry’ where…:
UPDATE students SET forename = ‘Harry’ WHERE…
Give the SQL command for: Delete a record from the students table
DELETE FROM students WHERE …
Give the SQL command for: Selecting from two tables
SELECT table1.attributeX , table2.attributeY
FROM table1 , table2
WHERE table1.primarykey = table2.foreignkey
AND …