Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1 Anant M 25
2 Babloo M 13
3 Manju F 30
4 Sibu M 12
5 Soma F 28
1
Suppose you want to sort the records in this file in increasing order of the AGE field. You have to
give the command at the dot prompt:
.USE BIODATA and press ENTER
. SORT ON fieldname TO new filename. Thus you have to give the command
. SORT ON AGE TO BIO and press ENTER
Here field name is AGE and the sorted file name is BIO.DBF
To see the contents of the sorted file give the following commands:
. USE BIO.DBF
. LIST
The sorted file BIO. DBF looks like as shown in Fig. 21.2.
. use biodata
. sort on age to bio
100% sorted 5 records sorted
. use bio
. list
Record# NAME SEX AGE
4 Sibu m 12
2 Babloo m 13
1 Anant m 25
5 Soma f 28
3 Manju f 30
Here you notice one thing that BIO.DBF is a new file. In this new file, the record numbers given
by database is in a new order. But Age field is in sequence, because you have sorted the
BIODATA.DBF to increasing order of the AGE field. Suppose you want to sort the file in
descending order of the AGE field. Then you have to give the command SORT ON AGE/D TO
TEMP.DBF. The new file TEMP looks like as shown in Fig. 21.3
. use biodata
. sort on age/d to temp
100% sorted 5 Records sorted
. use temp
. list
Record# NAME SEX AGE
1 Manju f 30
2 Soma f 28
2
3 Anant m 25
4 Babloo m 13
5 Sibu m 12
Fig. 21.3
. use biodata
. index on age to bioage
100% indexed 5 Records indexed
. list
Record# NAME SEX AGE
4 Sibu m 12
2 Babloo m 13
1 Anant m 25
5 Soma f 28
3 Manju f 30
DIFFERENCE BETWEEN SORT AND INDEX COMMAND
Sort Command Index command
• Creates a new database file Does not create a new file
• Arranges the records in ascending and Arranges the records only in ascending order
descending order
• File extension is .DBF File extension is .NDX
• Slower than index command Faster than sort command
• Renumbers records Does not renumber records
3
The FIND and SEEK commands both are used in indexed database. FIND operates with character
strings, while SEEK operates with either character string or numeric values. If SEEK operates with
a character string the string must be enclosed in a single or double quotes or square bracket Let us
take some examples
. USE BIODATA
. INDEX ON AGE TO BIOAGE
. USE BIODATA INDEX BIOAGE
. FIND 30
. DISPLAY
The screen will look like this
. use biodata
. index on age to bioage
. use biodata index bioage
. find 30
. display
Record# NAME SEX AGE
3 Manju f 30
The FIND command will move the record pointer to the first record which matches with find
query and the DISPLAY command will display it on the screen.
The SEEK command like FIND command also works only with an index file. When you SEEK
command with strings, you must use quotes. Consider the previous example, to SEEK the NAME
Manju, you must give the command
. USE BIODATA
. INDEX ON AGE TO BIOAGE
. USE BIODATA INDEX BIOAGE
. SEEK 30
. DISPLAY
The screen will look like this
.use biodata
. index on age to bioage
. use biodata index bioage
. seek 30
. display
Record# NAME SEX AGE
3 Manju f 30
4
The main difference between SEEK and FIND commands is that SEEK command will not work
with macros but FIND command is used in macros.
21.3.4 Counting Command
The COUNT command helps in finding the number of records in the active database that meet a
given condition.
. USE BIODATA
. COUNT FOR AGE> 13
The screen will appear as follows:
. use biodata
. count for age >13
3 records
. count
5 records
Fig 21.7
The COUNT command, without any condition, gives the total number of records in the active
database file.
. COUNT
The computer prompts
5 RECORDS
21.3.5 LOCATE Command
The LOCATE command is used to find the records in a database which satisfy certain conditions.
The general form of LOCATE command is
. LOCATE [scope] FOR [condition]
Suppose you give the command
. USE BIODATA
. LOCATE FOR AGE =25
The computer will prompt
RECORD =1
Your screen will appear like this
. use biodata
. locate for age=25
Record = 1
Fig 21.8
5
For displaying that particular record in a database give the command DISPLAY and if you want to
continue the search give the command CONTINUE along with LOCATE command. Your screen
will appear like this
. use biodata
. locate for age=30
Record = 3
. continue
End of LOCATE scope
Command Line ¦<C:>¦BIODATA ¦Rec: EOF/5 ¦ ¦
NAME Soma
SEX f
6
AGE 28
Fig. 21.10
After making the desired changes, pressing Ctrl+W saves the changes and exits to the prompt.
21 .4. 1 The Record Pointer
How did the EDIT command display only the 5th record? This can be explained by the concept of
a record pointer that is maintained for each file opened by dBASEIII+. When the file is open the
pointer points to the first record in the file and moves to the other records after a command has
been given. For example, with the LIST command, the record pointer moves to the end of the file,
since it moves successively from the first record to the last record. The current record (i.e., the
record on which the pointer is positioned currently) can be displayed by giving the command.
DISPLAY. This command is used to position a particular record, which is to be displayed.
. DISPLAY
DISPLAY [ALL!RECORD<recordno. >]
[<expr_list>] [FOR<expl.>] [TO PRINT]
where:
<expr_list> is a list fields or expressions.
<expl.> is a condition.
.USE BIODATA
.DISPLAY
dBASE will display only the first record along with header which we have discussed earlier.
Let us consider the following example
dBASE will display the 4th record in the file along with header.
. use biodata
. goto 4
. display
Record# NAME SEX AGE
4 Sibu m 12
.
Fig 21.11
The GOTO command followed by the record number moves the record pointer to a specified
record.
7
. GOTO 5
This command will position the pointer on the 5th record.
. GOTO<expN>
where <expN> is the record number.
. use biodata
. goto 5
. display
Record# NAME SEX AGE
5 Soma f 28
.
NAME Soma
SEX f
8
AGE 28
EDIT ¦<C:>¦BIODATA ¦Rec: 5/5 ¦ ¦
Filed Name Type Width Dec Filed Name Type Width Dec
1 NAME Character 10
2 SEX Character 1
3 AGE Numeric 2 0
Fig. 21.15
21. 6 MORE ON QUERIES
Instead of giving the List to Print command with each and every query, the printer can be activated
to print the command as well as the output of the command. The command that can be given to
activate the printer is as follows:
. SET PRINT ON
. LIST
To deactivate the printer the command is:
. SET PRINT OFF
21.6.1 Deleting Records
The delete command marks the current record for deletion. When the records are marked for
deletion they are not transferred during copy and sort operation. Now we will discuss how delete
command is used in different ways.
10
. DELETE RECORD 5 <marks record 5 for deletion>.
1 records deleted
The DELETE command also provides the following options:
OPTION DESCRIPTION
Now delete all the records in the active database file BIODATA. You will find an asterisk (*)
against the records marked for deletion.
. use biodata
. delete all
5 records deleted
. list
Record# NAME SEX AGE
1 *Anant m 25
2 *Babloo m 13
3 *Manju f 30
4 *Sibu m 12
5 *Soma f 28
.
Command Line ¦<C:>¦BIODATA ¦Rec: EOF/5 ¦ ¦
Type a command (or ASSIST) and press the ENTER key (-+).
Enter a dBASE III PLUS command.
In this example we delete the next four records from the active database file.
. use biodata
. delete next 4
4 records deleted
. list
Record# NAME SEX AGE
1 *Anant m 25
2 *Babloo m 13
3 *Manju f 30
11
4 *Sibu m 12
5 Soma f 28
Now we recall all the records marked for deletion in the active database file BIODATA. Notice
that the RECALL command unmarks the records, which were marked for deletion earlier.
. use biodata
. recall all
5 records recalled
. list
Record# NAME SEX AGE
1 Anant m 25
2 Babloo m 13
3 Manju f 30
4 Sibu m 12
12
5 Soma f 28
.
Command Line ¦<C:>¦BIODATA ¦Rec: EOF/5 ¦ ¦
Type a command (or ASSIST) and press the ENTER key (-+).
Enter a dBASE III PLUS command.
Fig. 21.18
21. 7 CLOSING AN OPEN DATABASE FILE
The USE commands without file name closes an open database file. Open database can also be
closed with the QUIT, CLEAR ALL, CLOSE DATABASE and CLOSE ALL commands.
IN -TEXT QUESTIONS 2
1. Differentiate between EDIT and BROWSE commands.
2. Bring out the uses of the following commands
DELETE
PACK
RECALL
REPLACE
USE
13
(ii) use
(iii) start
(iv) none of the above
(e) The modify structure command helps
(i) to change the structure of an active database file.
(ii) to remove the structure
(iii) to name the structure
(iv) none of the above
21.8 WHAT YOU HAVE LEARNT
In this lesson we discussed the procedures of organising a database. In this process we
distinguished between SORT and INDEX commands, FIND and SEEK commands, DELETE and
PACK commands, BROWSE and EDIT commands. Now you should be in a position to count the
number of records in a database and modify structure of a database.
21.9 TERMINAL QUESTIONS
1. What are the different methods of data organisation.? Explain briefly.
2. Write short notes on SEEK, FIND, GOTO, EDIT, RECALL and PACK commands.
3. Define SORT and INDEX command with suitable example.
4. What are the different steps involved in modifying a database, while using EDIT command?
5. Define COUNT command with example.
21.10 FEEDBACK TO IN-TEXT QUESTIONS
IN-TEXT QUESTIONS 1
1. Files can be arranged in either ascending order or descending order by using SORT command.
But incase of INDEX command you can arrange the file only ascending order. Index command
does not create a new database file. But SORT command creates a new database file.
2. FIND operates with character strings, while SEEK operates with either character string or
numeric values.
3. (a) The COUNT command helps in finding the number of records in the active database
that meet a given condition. Example:
. USE NAME
. COUNT FOR AGE> 11
(b) The LOCATE command is used to find the records in a database which satisfy certain
conditions. Example:
. USE BIODATA
. LOCATE FOR AGE=18
IN-TEXT QUESTIONS 2
1. EDIT command displays one a particular record that is the record at the cursor position. But
BROWSE command displays all the records in the database file.
14
2. DELETE: marks the record for deletion.
PACK: Permanently deletes the records from the database file, which were earlier marked for
deletion by DELETE command.
RECALL: Unmarks the record marked earlier.
REPLACE: used to REPLACE the contents of one or more specified field
USE: Closes the active database file.
3. (a) i
(b) iii
(c) iii
(d) ii
(e) i
15