02 Section 5 - File Handling and Storing Data Flashcards

You may prefer our related Brainscape-certified 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
Q

What is the first thing every database needs?

A

a table

26
Q

What is the SQL statement for creating a table?

A

CREATE TABLE tablename (primarykeyfieldname DATATYPE PRIMARY KEY, fieldname2 DATATYPE, fieldname3 DATATYPE … );

27
Q

What do you need to specify for each field in a table?

A

The data type

28
Q

What are common SQL data types?

A
INTEGER
REAL
TEXT
DATE
BOOLEAN
29
Q

What is the SQL statement for adding complete records to an empty table?

A

INSERT INTO tablename VALUES (data, data2, data3 …);

30
Q

What is the SQL statement for adding incomplete records to an empty table?

A

INSERT INTO tablename (field, field2, field3 …) VALUES (data, data2, data3 …);

31
Q

What is the SQL statement for updating a record?

A

UPDATE tablename SET field = data WHERE primarykeyfieldname = number;

32
Q

When retrieving information from a database wheat are the key SQL statements?

A

SELECT

FROM;

33
Q

What does a SELECT statement in SQL do?

A

Used to tell the database what information you want it to retieve

34
Q

What does a FROM statement in SQL do?

A

Tells the database which tables to look in

35
Q

What is the SQL statement for retrieving data from a database?

A

SELECT field, field2 …

FROM tablename;

36
Q

What is the SQL wildcard for all the fields?

A

*

37
Q

Why do you use a WHERE SQL statement?

A

To specify conditions that a record must satisfy before it is returned

38
Q

What is the SQL statement for retrieving data from a database with specified conditions?

A

SELECT * FROM tablename

WHERE condition;

39
Q

What conditions can be used with the WHERE SQL statement?

A

Comparison operators
Boolean operators - AND, OR
LIKE statements (to search for a pattern)

40
Q

What are the SQL wildcards you can use?

A
  • (to return all fields)

% (used in LIKE statements to represent any combination of letters or numbers)

41
Q

What is the SQL statement for retrieving data from a database with specified conditions of partial information?

A

SELECT * FROM tablename

WHERE field LIKE “%parital information%”;

42
Q

What is the SQL statement for retrieving data from a database in an order?

A

ORDER BY field ASC;

-sort records ACS (ascending) or DECS (descending) order