02 Section 5 - File Handling and Storing Data Flashcards

1
Q

What is the first thing you have to do when dealing with file handling?

A

Open the external file using an open command and assigning it to a variable

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

What is an open command in Read mode?

A

newFile = openRead(“newfile.txt”)

-sometimes you have to give the whole file path, not just the file name

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

What is an open command in Write mode?

A

newFile = openWrite(“newfile.txt”)

-sometimes you have to give the whole file path, not just the file name

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

What are the two modes you can open files in?

A

Read

Write

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

What is read mode for opening a file?

A

It allows you to read data from the external file into your program

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

What is write mode for opening a file?

A

It allows you to write data from your program to an external file

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

When a file is opened where does it start reading or writing from?

A

The beginning of the file

-as you read from or write to the file, the program keeps its place in the file

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

What is the last thing you should do when dealing with file handling?

A

You should close the file

-if you forget to close it then a file can remain locked and prevent others from editing it

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

What is the close command for file handling?

A

newFile.close()

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

How can you write to a file once it is opened?

A

newFile.writeLine()

-if the file already contains some text, then it will overwrite what is currently there

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

How can you read from a file once it is opened?

A

newFile.readLine()

-the program will always start reading from the first line of the external file

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

What is the file handling command which returns TRUE when the program is at the end of an external file?

A

newFile.endOfFile()

-used to signify when a program should stop reading a file

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

What do data bases order data into?

A

Fields (columns) and records(rows)

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

What do databases store data in?

A

Tables, made up of fields and records

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

What is a field?

A

A field is used to store a category

-a column of the table

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

What is a record?

A

A record uses the field to store details about a specific item
-a row of the table

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

What is the difference in data types between fields and records?

A
  • all data in the same field has to have the same data type

- all data in the same record can have different data types

18
Q

What does each table in a database have?

A

a primary key

19
Q

What is a primary key?

A

A field which can uniquely identify any record in the table

-there is only one primary key field per data base table

20
Q

What are the two types of database?

A

flat-file

relational

21
Q

What is a flat-file database?

A

Databases that only have one table, which can be viewed by opening one data file

22
Q

What is a relational database?

A

Databases that combine flat-file databases, the different tables are linked together by key fields

23
Q

What does SQL stand for?

A

Structured query language

24
Q

What is SQL?

A

A language that can create, update and query databases

-it consists of commands called statements

25
What is the first thing every database needs?
a table
26
What is the SQL statement for creating a table?
CREATE TABLE tablename (primarykeyfieldname DATATYPE PRIMARY KEY, fieldname2 DATATYPE, fieldname3 DATATYPE ... );
27
What do you need to specify for each field in a table?
The data type
28
What are common SQL data types?
``` INTEGER REAL TEXT DATE BOOLEAN ```
29
What is the SQL statement for adding complete records to an empty table?
INSERT INTO tablename VALUES (data, data2, data3 ...);
30
What is the SQL statement for adding incomplete records to an empty table?
INSERT INTO tablename (field, field2, field3 ...) VALUES (data, data2, data3 ...);
31
What is the SQL statement for updating a record?
UPDATE tablename SET field = data WHERE primarykeyfieldname = number;
32
When retrieving information from a database wheat are the key SQL statements?
SELECT | FROM;
33
What does a SELECT statement in SQL do?
Used to tell the database what information you want it to retieve
34
What does a FROM statement in SQL do?
Tells the database which tables to look in
35
What is the SQL statement for retrieving data from a database?
SELECT field, field2 ... | FROM tablename;
36
What is the SQL wildcard for all the fields?
*
37
Why do you use a WHERE SQL statement?
To specify conditions that a record must satisfy before it is returned
38
What is the SQL statement for retrieving data from a database with specified conditions?
SELECT * FROM tablename | WHERE condition;
39
What conditions can be used with the WHERE SQL statement?
Comparison operators Boolean operators - AND, OR LIKE statements (to search for a pattern)
40
What are the SQL wildcards you can use?
* (to return all fields) | % (used in LIKE statements to represent any combination of letters or numbers)
41
What is the SQL statement for retrieving data from a database with specified conditions of partial information?
SELECT * FROM tablename | WHERE field LIKE "%parital information%";
42
What is the SQL statement for retrieving data from a database in an order?
ORDER BY field ASC; -sort records ACS (ascending) or DECS (descending) order