SQL queries Flashcards
Define SQL
Text-based querying system used in all relational database management systems
Common datatypes for SQL
VARCHAR(n) - String with max n amount
TEXT - String with max length of 65535 characters
INT(n) - Integer with max n amount
FLOAT(n,d) - Small number with decimal point. n = max digit. d = number of digits right of decimal point
DATE - Date written in YYYY-MM-DD
DATETIME - Date + Time written in YYYY-MM-DD HH:MM:SS
TIME - Time written in HH:MM:SS
BOOLEAN - True/False
When creating a table what do you need to do
Assign a primary key - Done by stating after assigning a datatype
Things to remember when inserting a record
Values need to be in same order as table
Use commas to separate each entry
How to remove duplicates in records
You would use DISTINCT after the SELECT
E.g
SELECT DISTINCT teacher
FROM classes
What relational operators can you use
=
>
<
<> <—— means not equal to
>=
<=
What logical operators can you use
AND
OR
NOT
IS NULL
BETWEEN… AND…
LIKE<—– Customername LIKE ‘B%’ - gives customers that start with B
IN
How to select with more than one table
Need to test the JOIN by linking two clauses. To give a result to only those combination of records. Represent true enrolments of students in classes