• Keine Ergebnisse gefunden

DUPLICATING FILES

Im Dokument dBase n User's Guide (Seite 139-150)

Working With The Data Base Structure

DUPLICATING FILES

It is a good idea to keep backup copies of important data files. To duplicate dBASE II files without exiting to the CP 1M operating system, use the COPY command. To see how this works, enter:

use jobdet copy to jobtemp use jobtemp display structure list

As you can see on the screen that follows, this command sequence copies the entire JOBDET.DBF file, the record structure and all data records except those marked for deletion. The DISPLAY and LIST commands are not necessary for performing the COpy. They are included for demonstration purposes only.

Working with the Data Base Structure

use jobdet copy to jobtemp 00010 RECORDS COPIED

use jobtemp display structure

STRUCTURE FOR FILE: JOBTEMP.DBF NUMBER OF RECORDS: 00010 DATE OF LAST UPDATE: 11/04/82 PRIMARY USE DATABASE

FLO NAME TYPE WIDTH DEC 00006 p3 Programmer 15750.00 25000.00 00007 p4 Prog/Analyst 17000.00 26500.00 00008 p8 Sr Programmr 20000.00 28000.00 00009 p9 Sr PrgAnLyst 27500.00 36000.00 00010 s8 Typist 10640.00 17640.00

Selective Copies

The general form of the COpy command is:

COPY TO <file> [<scope>] [FIELD <field list>] [FOR <exp>]

Since the command takes qualifying phrases, it can be used to copy whole files or to copy selectively. The command is written according to the following rules.

• The file name can be either a new or existing file.

• If the file does not exist, it is created.

• If the file does exist, its structure and contents are completely replaced by the structure and contents of the file in USE.

Working with the Data Base Structure

• The new file has the same file type extension (for example, ".DBF") as the file from which it is copied.

• The scope parameter defaults to ALL.

• If a list of fields is supplied, those data fields are the only ones copied to the new file. The keyword FIELD must be used. The field names in the field list must be separated by commas.

• Records marked for deletion are not copied.

DELETING AND RENAMING FILES

At this point, there are more files on your dBASE II diskette than you need. There are" original" files, files sorted into various sequences, backup copies, and so on.

It is a good practice to delete unnecessary files to free up.space and avoid confusion.

At the same time, it is a good idea to make backup copies of data files. To keep appropriately labelled copies of data files, use the COpy command with the DELETE and RENAME commands described in this section.

To remove files from the diskette, use the DELETE command.

DELETE FILE [<disk drive>:]<file>

Deleting files is a one-step process. Once this command is executed, the entire file is gone forever. It cannot be recalled. dBASE II includes two features that help prevent the accidental deletion offiles. The keyword FILE must be entered, and you cannot DELETE a file that is currently in USE.

ABCORDER.DBF and TEMP.DBF are demonstration files created in Chapter 3 to hold PEOPLE records sorted in different orders. JOBDET.DBF is the job details file with records marked for deletion. Since you don't need these files and a few others, delete them by entering the following sequence of commands.

Working with the Data Base Structure

The USE command closed any open files. LIST FILES was included in the sequence to verify that the files were DELETEd. All the DELETEd files were data base files (type DBF)so it was not necessary to include the file type extension as part of the file name. For any other file types, the command requires the full file name. When files are not on the default drive, the drive specifier (disk drive:) must prefix the file name.

Working with the Data Base Structure

DELETE removes the file name from the CP/M directory and frees space on the diskette. Use this command to remove temporary files, SORT files, and any other unneeded files from diskettes.

Renaming Files

The file named JOBTEMP.DBF is the cleaned up version of the job details file.

JOBDET.DBF is a better name for the file. It is more descriptive and is the name the file has been called throughout this guide. Since the JOBDET.DBF file has been deleted, you can change the name of JOBTEMP.DBF to JOBDET.DBF with the RENAME command.

RENAME <orig file> TO <new file>

This command changes the name of a file in the CP/M directory. ~f no file type extension is given, dBASE II assumes that the type is DBF. Although it is' possible to change the file type along with the name, it is generally not a good practice to do so. Backups are the exception. The extension ".BAK" is conventionally used to identify backup copies of files.

Rename the JOBTEMP file to JOBDET as shown in the following screen.

Working with the Data Base Structure

• use jobtemp

• reneme jobtemp to jobdet

• list fi les DATABASE FILES PEOPLE DBF EMPLOYEE DBF JOBDET DBF

# ReDS 00006 00017 00010

LAST UPDATE 00/00/00 10/31/82 00/00/00

WARNING

Do not RENAME a file that is in USE.

Maximizing Diskette Space

The PACK command described in Chapter 7 removes deleted records from a file but does not release the freed space on the diskette. To release the space, use the following procedure:

1. USE the original file. This is the file that has been PACKed or that has records marked for deletion.

2. COpy the original file to a new file.

3. DELETE the original file.

4. RENAME the new file with the original file name.

Working with the Data Base Structure

Backup Procedures for a Dual-Drive APC

With the three commands just described, you can create backup copies of individual files with appropriate names. If you have a dual-drive APC, you can create backup data files on a diskette kept for just that purpose. Individual files can be copied from within dBASE II. The following is a suggested backup sequence for a dual-drive system.

1. If the data file to be copied is on Drive A with the dBASE II program, skip this step. Otherwise, COPY B:<file> TO A:<temp>.

2. Insert the formatted backup diskette in Drive B.

3. COPY A:<temp> TO B:<backup>

4. Remove the backup diskette from Drive B.

5. Take appropriate action with the original file. This can mean doing nothing, renaming the file, or deleting it.

6. If the data file was copied to Drive A in Step 1, delete it: DELETE A:<temp>.

As an alternative, you can create backup copies of files using the 'CP/M-86 Peripherals Interc.hange Program (P1P). To use this procedure, you must exit from dBASE II. (See the CP/M-86 System User's Guide for information on howto use this program.)

Backup Procedures for a Single-Drive APC .

If you ha ve a sinBle-drive APC, you must exit from dBASE II and use the CP 1M -86 Peripherals Interchange Program (PIPI) to copy files from one diskette to another.

(See the CP/ M-86 Systems User's Guide for information on how to use this program.)

CHANGING THE DATA BASE STRUCTURE

The structure of a data base and its contents are two separate, but related, entities.

So far, you have used commands to manipulate either the data base contents -records - or the entire data base file. This chapter describes procedures for working with the data base structure.

There are many ways to add and delete fields in a data base structure. The best method is the one that has the lowest probability of error and results in the least work for you. All methods should involve the same basic steps. Start by creating a new data base structure in a temporary file. Then, bring the data from the original file into the new, modified structure.

Working with the Data Base Structure

Generating the Structure

You can define the new structure with the CREATE command or CO PY the structure of an existing file and MODIFY it.

CREATING THE STRUCTURE FROM SCRATCH

Assume you have the job of compiling a telephone list of all employees in the personnel data base. To do ·this, you could CREATE a new file, PHONELST, consisting of four fields: last name, first name, department number, and telephone number.

USING EXISTING DATA

Then, instead of entering name and department number data from the keyboard, you could copy the values from the EMPLOYEE file using a new form of APPEND.

(You would have to fill in the telephone numbers another way.) APPEND FROM <file> [FOR <exp>]

The records to be APPENDed are taken from an existing file.

dBASE II reads the structures of both files and looks for fields with matching names. It then transfers data from the "FROM" file to the file that is in USE for the fields that match.

This sequence is illustrated in the following screen.

Working with the Data Base Structure

• create phonelst

ENTER RECORD STRUCTURE AS FOLLOWS:

FIELD NAME,TVPE,WIDTH,DECIMAL PLACES 001 last:name,c,8

append from employee 00017 RECORDS ADDED included. To APPEND the names of only those employees in department 54, you could use the command:

append from employee for dept:num='54'

When the FOR phrase is used, dBASE II APPENDs the records in the FROM file one by one, each time checking to see if the condition in the FOR expression is true.

That is, the first record is appended. Then the expression is evaluated. If the expression is true, the record is kept. If the expression is false, the record is discarded. This procedure continues until the end-of-file is reached for the FROM file. This means that the fields used in the expression must reside in the file receiving the new records.

Working with the Data Base Structure

MODIFYING AN EXISTING STRUCTURE

When only one or two fields from an existing data base are needed in the new file, it is efficient to CREATE the new structure. However, the sequence of COpy STRUCTURE and then MODIFY STRUCTURE is probably the fastest and easiest way to add, delete, rename, resize, or otherwise change a data base file structure.

The following format of the COpy comIl1and duplicates a file structure.

COpy STRUCTURE TO <file> [FIELD <field list>]

All or part of the structure can be copied. To copy selectively, use the optional FIELD phrase. List the names of fields from the original file that are to be included in the new structure. Commas are required in the field list to separate names.

As an alternative to the CREATE and APPEND sequence described previously, you can use COPY STRUCTURE to copy only the last name, first name, and department number fields from the EMPLOYEE file structure, as shown in the following screen.

Working with the Data Base Structure

• use empLoyee

copy structure to temp fieLd Last:name, first:name, dept:num use temp

• modify structure

MODIFY ERASES ALL DATA RECORDS ... PROCEED? [YIN] Y

This copies only two fields from the structure of the EMPLOYEE file. No data records are copied. Once the structure has been copied without data records, it can be changed with the MODIFY STRUCTURE c.ommand.

WARNING

The MODIFY STRUCTURE command de-letes all data records that were in the USE file prior to the MODIFY. It should only be used with empty data bases. Use this command only after copying the structure.

Working with the Data Base Structure

MODIFY STRUCTURE acts upon the data base currently in USE. Since it destroys all data records, the system prompts you to be sure this is what you want to do before it takes any action. If you respond that you want to continue, the display screen is erased and up to 16 fields of the existing structure are displayed.

FIELD

You can make changes in full-screen edit mode using the commands listed in Table 8-1. Two commands are especially useful:

CTRLN

Im Dokument dBase n User's Guide (Seite 139-150)