Download presentation
Presentation is loading. Please wait.
1
Updating Records in a Table
Chapter 5 Updating Records in a Table Sept cylau Foxpro Chapter 5
2
Updating a table Updating a table refers to editing (changing) records, adding new records (inserting) or deleting records. Contents in a table can be changed interactively using the BROWSE or EDIT Windows. Alternatively they can be changed using a FoxPro command. Sept cylau Foxpro Chapter 5
3
Updating vs. Querying Updating: Querying:
changing the data value within a table or the structure of the table itself. Querying: reading data values but not changing them. Sept cylau Foxpro Chapter 5
4
Ways to update Editing && fields of a record Inserting && a record
Deleting && a record Importing && a file Exporting && a file Summing && numeric fields Sept cylau Foxpro Chapter 5
5
EDITING Records can be changed in the Browse/Edit Windows, or they can be changed using the Replace command Sept cylau Foxpro Chapter 5
6
Replace Several Fields
USE project ... REPLACE date WITH {01/03/2010},; maxTemp WITH 22, minTemp WITH 16 Further Practice 4 Q.1 Sept cylau Foxpro Chapter 5
7
Replace All Records or Certain Records
USE formPos Further Practice 1A Q.5 ... REPLACE position WITH RECNO() ALL USE patient Further Practice 5A Q.5 REPLACE name WITH ‘Mr. ’+name FOR sex =‘M’ Sept cylau Foxpro Chapter 5
8
Replace Contents of Memo
Let remark be a field of memo type in table student USE job REPLACE remark with; ‘Urgent. Delay more than one week!”; ADDITIVE for … Further Practice 8A Q.2 Sept cylau Foxpro Chapter 5
9
BLANK USE project … BLANK FIELDS minTemp, maxTemp, ; range, aveTemp ALL Further Practice 4A Q.5 Sept cylau Foxpro Chapter 5
10
INSERTING New records can be added to a table by using the command APPEND
Sept cylau Foxpro Chapter 5
11
APPEND Put an additional record at the end of the table.
Open an input window for you to key in data. If an index is in effect, the record will immediately be moved to its appropriate location. Usually used interactively. Sept cylau Foxpro Chapter 5
12
APPEND BLANK Put an additional record to the end of the table.
If an index is in effect, the record will immediately be moved to its appropriate location. Usually used in programs. Sept cylau Foxpro Chapter 5
13
DELETING Sept cylau Foxpro Chapter 5
14
DELETE and PACK Use anyfile go 2
DELETE && The 2nd record is marked for deletion (logically deleted) PACK && The 2nd record is permanently deleted (physically deleted) Sept cylau Foxpro Chapter 5
15
SET DELETE ON SET DELETE ON DELETE ALL LIST && no records will be seen
SET DELETE OFF && default LIST && all records will be shown Sept cylau Foxpro Chapter 5
16
RECALL DELETE ALL && mark all record for deletion
RECALL ALL && unmark all Sept cylau Foxpro Chapter 5
17
DELETED() USE student Go 2 DELETE ? DELETED() && output .T. RECALL
? DELETED() && output .F. Sept cylau Foxpro Chapter 5
18
DELETED() To browse only records marked for deletion: USE student
BROWSE FOR DELETED() = .T. or, BROWSE FOR DELETED() Sept cylau Foxpro Chapter 5
19
PACK Physically remove all records marked for deletion.
Cannot be recovered or recalled. Can you think of a way to recover the physically deleted records? Sept cylau Foxpro Chapter 5
20
ZAP Equivalent to DELETE ALL PACK No record is left
The table is empty but not the .DBF file The .DBF file still holds information about the structure of the table The .DBF file is the same as that formed by COPY STRUCTURE Sept cylau Foxpro Chapter 5
21
COPY STRUCTURE Use f1 COPY STRUCTURE TO f2 USE student
COPY STRUCTURE TO namelist FIELDS class, classno, name Sept cylau Foxpro Chapter 5
22
IMPORTING Sept cylau Foxpro Chapter 5
23
APPEND FROM a delimited file
USE student APPEND FROM newstxt TYPE DELIMITED A delimited file is an ASCII text file in which records are separated from one another by a carriage return and linefeed. Field contents are by default separated by commas. Sept cylau Foxpro Chapter 5
24
APPEND FROM a SDF file USE student APPEND FROM newssdf TYPE SDF
SDF stands for System Data Format in FoxPro. An SDF file is an ASCII text file in which records have a fixed length and end with a carriage return and linefeed. Fields are not delimited. Each row of data in the SDF is filled into a record according to the width of each fields Sept cylau Foxpro Chapter 5
25
APPEND FROM [a dbf file]
USE complex APPEND FROM temp Further Practice 6A Q.5 Sept cylau Foxpro Chapter 5
26
APPEND FROM an excel file
USE student APPEND FROM newsxls TYPE XL5 With our machines, Excel files can be imported only if they are of version 5 or earlier. If the source file is in Excel97 or newer version, first save it in Excel95 version. Sept cylau Foxpro Chapter 5
27
EXPORTING Sept cylau Foxpro Chapter 5
28
COPY FILE CLOSE ALL COPY FILE anyfile TO newfile
anyfile must not be open. wildcard characters are not allowed. The filenames concerned must contain extension if there are any. Behind the screen: FoxPro call the OS to perform a DOS copy or something similar. Sept cylau Foxpro Chapter 5
29
COPY TO USE student COPY TO studback USE f2001
COPY TO f2002 FOR PROMOTED=.T. COPY TO repeater FIELDS class, classno, name FOR PROMOTED=.F. Sept cylau Foxpro Chapter 5
30
Exporting to text files
USE student COPY TO stcomma.txt TYPE DELIMITED COPY TO stsdf.txt TYPE SDF Sept cylau Foxpro Chapter 5
31
Exporting to Excel 5 USE student COPY TO stxls.xls TYPE XL5
Sept cylau Foxpro Chapter 5
32
SUMMING Sept cylau Foxpro Chapter 5
33
TOTAL The total command computes totals for numeric fields in the table currently in use. The results will be stored in a newly created table with the same structure (by default) as the one in use. Sept cylau Foxpro Chapter 5
34
TOTAL Records should first be arranged in groups
In this case class should be grouped USE APStud TOTAL ON class FIELDS award_cnt, ; punish_cnt TO result Further Practice 7A Q.5 Sept cylau Foxpro Chapter 5
35
TOTAL For non-numeric fields, values in the first record of each group will be shown (In SQL, that of the last record is shown). This can be quite misleading in most circumstances. If only numeric fields and non-numeric fields with consistent value within each group are shown, the result will be more satisfactory. Sept cylau Foxpro Chapter 5
36
Backing Up Grandfather-Father-Son Concept
see p Done by you, not the computer Use 3 tapes A, B and C f1 --> f2 --> f3 --> f4 A --> B --> C --> A grandfa --> father --> son data in f1 are lost as tape A is overwritten with data in f4 Sept cylau Foxpro Chapter 5
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.