All topics covered in Y9 computer science: databases, python, logic gates
Table
a collection of related data sorted in an organized way. Made up of fields and records
Record
all of the data relating to one instance of the table, represented by a row e.g. Sophia Austin
(don’t say that it is a row)
Field
an attribute which all records have in common, represented by a column e.g. date of birth
(don’t say it is a column)
Query
a request for information - a way to access information from a database
Primary key
a special field that stores a unique value (an ID) for each record
CREATE TABLE statement line 1
CREATE TABLE table_name (
‘CREATE TABLE’ and the table name, then open brackets
CREATE TABLE statement lines for fields
text_field_name VARCHAR(30),
text_field_name VARCHAR(30),
integer_field_name INT,
decimal_field_name FLOAT,
true_or_false_field_name BOOLEAN
(indented)
Name of your first field (column), and after it what type of data you’ll be entering in it, e.g. text or numbers. For a text field you need to say how many characters it should allow as maximum. You put this number in brackets
Repeat for all the fields in the table
CREATE TABLE statement last line
);
This closes off the list
INSERT INTO statement first line
INSERT INTO table_name
‘INSERT INTO’ and then your table name
INSERT INTO statement second line
VALUES
INSERT INTO statement lines for values
("Text 1",44,55,33,1),
("Text 2",77,11,99,0),
("Text 3",29,100,21,8)
write a list of values to put into your table, each line is one record (row), and each field is separated by commas
quotes around any text data
INSERT INTO statement last line
;
SELECT FROM statement first line
SELECT * FROM table_name;
‘SELECT * FROM’ and then your table name and a ;
SELECT Firstname,Email FROM table4
What will this give you
All the firstnames and emails from table4
SELECT table4.Firstname, table4.email
What will this give you
All the firstnames and emails from table4
This is just another way of doing it, specifying each time which table you want it from instead of once at the start
SELECT Firstname FROM table_name WHERE surname="abe";
What will this give you
will give you all the firstnames in the table that have surnames containing ‘abe’, but not the surname
if you want it to display that you have to put it after a comma next to the firstname
function of => (SQL)
greater than or equal to
function of <= (SQL)
less than or equal to
function of <> (SQL)
not equal to
SQL: VARCHAR data type
a string of variable length (can contain letters, numbers and special characters). After it you put the maximum character length in brackets
SQL: INTEGER (aka INT) data type
a number
SQL: DECIMAL data type
an exact number with a fixed amount of digits and a fixed amount of digits after the decimal point, written as DECIMAL(digits, digits after decimal point)
SQL: BOOLEAN (aka BOOL) data type
true or false, 0 is false and anything else it true
Variable
a named memory location, used to store a value while the program is running. The value can change whilst the program runs
Operator
a symbol that takes one or more values and yields another value e.g. addition
Python: string data type
text
Python: integer (int) data type
number(s)
Python: float data type
a decimal
Python: boolean data type
true or false
1 = true
0 = false
* maths operator (python)
multiplication
** maths operator (python)
to the power of
// maths operator (python)
division, rounds the result down to the nearest whole number
% maths operator (python)
gives you the remainder of the first number divided by the second
== operator (python)
equal (not with numbers)
!= operator (python)
≠ (not equal to)
NOT gate
gives the opposite of what was put into it
AND gate
needs both inputs to be 1 to have an output of 1, anything else will give 0
OR gate
Will give 1 if either or both imputs are 1, will give 0 if both are 0
Definite iteration
when a code is repeated a specific number of times (for loop)
Indefinite iteration
when a code is repeated until a condition is met/no longer met
Iterating over a list
printing every item in that list
Range function (python)
prints every number in the range you specified (not including the number that you put, including 0)