CS8: Relational Databases & SQL Flashcards
What is a database?
A database is a way of organising data in a structured way.
What is the difference between a relational database and a flat file database?
A flat file database’s tables have no relations and no keys, whereas a relational database can have connections via primary and foreign keys.
What is a table?
A series of records composed in an organised way
What is a record?
Usually represented by rows, a record is data that has multiple parts to it. All information on a single user on a database would be a record.
What is a field?
Usually represented by columns, fields are a small subsection of data in a record. An example might be a user’s phone number.
What are primary and foreign keys?
A primary key is a unique identifier for each record in a table.
A foreign key is a primary key from another table, and is used to refer to a record in another table.
What is a database relationship?
A database relationship describes how tables in a relational database connect to one another. They are formed using primary & foreign keys.
What does SQL stand for, and what is it used for?
SQL, or structured query language, is a programming language used to find and manipulate data in a database.
What are some of the “good-practice” rules of SQL?
Good-practice rules:
- Write commands in CAPITALS
- Write tables as tbl[name] (e.g. tblDownloads)
- Put new commands on a new line
How do you query a database?
SELECT which fields you want to see
Where they are FROM
and WHERE certain conditions are met
SELECT * (* = all)
FROM tblRegistry
WHERE date > “01/01/2001”
What are the three primary logic operations?
Where condition one is true AND condition two is true
Where condition one is true OR condition two is true
Where field is BETWEEN value one AND value two
WHERE time >= “17:30” AND MemberID < “50”
WHERE time >= “17:30” OR MemberID < “50”
WHERE time BETWEEN “17:30” AND “23:00”
When working with multiple tables in a database, how do you refer to fields?
You refer to them as table_name.field_name
i.e. tblDownloads.DownloadTime
When working with multiple tables in a database, how do you form a relationship?
You specify in the WHERE segment that tableone_name.Foreign_Key = tabletwo_name.Primary_Key
For example:
WHERE tblDownloads.MemberID= tblMembers.MemberID
How do you insert data using SQLite?
You choose the table you want to INSERT INTO, and the (fields you want to insert)
You then input the VALUES you want to insert
INSERT INTO tblDownloads (Date, Track)
VALUES (“03/07/2008”, “Mulberry Sky”), (“23/02/2013”, “Time of dusk”);
How do you update data using SQL?
You choose the tables you want to UPDATE
And choose the fields you want to SET
Then choose WHERE you want the values to be updates.
UPDATE tblUsers
SET password = “password123”
WHERE UserStatus = “empty”;