SQL queries Flashcards

1
Q

Define SQL

A

Text-based querying system used in all relational database management systems

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

Common datatypes for SQL

A

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

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

When creating a table what do you need to do

A

Assign a primary key - Done by stating after assigning a datatype

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

Things to remember when inserting a record

A

Values need to be in same order as table
Use commas to separate each entry

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

How to remove duplicates in records

A

You would use DISTINCT after the SELECT
E.g

SELECT DISTINCT teacher
FROM classes

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

What relational operators can you use

A

=
>
<
<> <—— means not equal to
>=
<=

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

What logical operators can you use

A

AND
OR
NOT
IS NULL
BETWEEN… AND…
LIKE<—– Customername LIKE ‘B%’ - gives customers that start with B
IN

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

How to select with more than one table

A

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

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