Embed Size (px)
Transcript of FoxPro Database
Are You suprised ?
WHAT IS A DATABASE?PRIVATE
The term database describes a collection of data organized in a manner that allows access, retrieval ,and use of that data. A database is a structure that can hold data concerning many different types of objects (technically called entities)as well as relationships between this objects. For example a companys data may hold data on such objects as sales reps and customers. In addition ,the database would include the relationship between sales reps and customers; That is ,we could use the data in the database to determine the sales rep who represents any particular customer and to determine all the customers who are represented by any given sales rep.
Below is an example of a database.
PRIVATE NAMESUBJECT GRADE
In essence tables form a sort of database even when they are on paper. A database management system or DBMS is a software product that can be used easily to create a database; make additions, deletions, and changes to data in the database; sort the data in the database; and retrieve data from the database in a variety of ways. Foxpro is the most widely used DBMS. Foxpro is a data processing program. The columns for the name the subject and the grade are called fields in foxpro. Fields simply contain related information. The name column would be in foxpro a character column so would the subject column. The grade column however will be a numeric field. You can have in addition, date,logical and memo fields.
To load foxpro use the DOS CD command to gain entry into the directory which contains the foxpro program files eg CD FOXPRO2 from the hard disk. Type FOX at the dos prompt to start the program.
In foxpro you can work from two modes the assistant or the dot prompt.
PLANNING A DATABASE FILE.Before using foxpro to create a database file you must perform four steps
1.Select a name for the database.
2.Define the structure of the database.
3.Name the fields.
4.Determine the type and the width of each field.
NAMING A DATABASEThe name can be up to 8 characters but not more. You should select names which are as meaningful as possible.
Defining the structure of a databaseYou must determine the fields that will make up the file. The fields you want to include must be based upon the type of information you want to extract from the database. To make a database for employees,lets call it EMPLOYEE. We will require information on the employee number the employee name ,the date hired ,the department name ,the pay rate ,and the field that tells whether or not the employee is a member of the union. In foxpro you can have a maximum of 128 fields and records can be a maximum of 400 characters long.
NAMING THE FIELDSYou must assign a unique name to each fields in the database.
A field name can contain up to 10 characters
-No blank spaces are allowed
Below is a chart which illustrates the field names that will be used in the sample file.
FIELD NAMEEMPLOYEE NUMBER
DEFINING FIELD TYPES1.Character fields
These fields may be used to store any printable characters that can be entered on the keyboard.
2.Date fieldsThese are used to store dates
3.Numeric fields These fields are used to store integer or decimal numbers
4.Logical fieldsThese consist of a single value representing a true or false condition. The entry must be T for true or F for false,or Y for Yes and N for No.
5. Memo fieldsMemo fields are used to store large blocks of text such as words or sentences.
Indicating width and Decimal PositionThe width of the field indicates the maximum number of characters that will be contained in the field.
THE ASSISTANTThe assistant is a collection of menus that help you in processing the data in a database.
When you use the menus you are in the assist mode. The names of the various menus are displayed across the top of the screen.
In foxpro they are:
-System, File, Edit, Database, Record , Program and Window.
You can invoke each of this menus by pressing ALT+ letter key combination. For instance to invoke the file menu, you press ALT + F. You navigate the highlight bar by using the right, left, top and bottom arrow keys to move in the right direction.
To create a database file simply move the cursor to the File menu and select New in foxpro. In foxpro enter over the "Create" menu under the item "Data".
You have to provide a name for the database file in foxpro and where it is to be placed. In foxpro this will come after you have made the database structure.
THE COMMAND PROMPTFrom the menus you can move to the dot prompt by pressing the ESC key. In foxpro the change will be immediate. At the prompt which is also known as the command prompt you will view the commands that you enter and also will be allowed to enter new commands. When you use the menu foxpro actually constructs the commands for you whereas when you use the command prompt you have to input the commands yourself.
QUITTINGTo quit foxpro simply type Quit at the dot prompt or press ALT+ F to access the menu , move the highlight to the quit option and press the enter key.
GETTING HELPIf you need additional help simply press F1 from either the dot prompt or the assist and you will be moved immediately to the help feature of foxpro. press enter over any highlighted object and you will get more information about that topic. You can navigate over the different choices using the arrow keys until you have reached the selection you want.
CREATING A FILE.- At the File menu press the enter key. A database design screen appears.
- Enter "name" in the first prompt to create the first field , ie the name field. Accept the default character field type.
-Enter 15 in the width column and press enter.
Repeat the above steps for the field information shown below
To change the field type simply press the Enter key and press enter over the right selection.
Type "Employee" in the Prompt that appears as 'save as' for the name of the file. Press CTRL + W to proceed to save the database and exit.
Entering and editing data.ADDING NEW RECORDS TO A FILE.You can enter information for new records through either a browse or edit screen. To switch from either the browse screen to the edit screen type Browse or Edit at the dot prompt.
TO ADD A NEW RECORD:-Press ALT +R to invoke the Records menu. From the records menu , select the Append option. A blank record is displayed ready for infilling. You can now enter data into each field. For the employee database file enter the following information.
Rapoza ,Anthony P.
After one record is full the record pointer moves to the next blank record.
fill in the rest of the information.
DEPARTMENTPAYRATE UNIONMcCormack L.1013
Doi Chang J.1017
EDITING EXISTING DATAYou will usually have to update data in your database sooner or later.
Changing data in a database.You can edit in the Browse screen as easily as in an Edit screen. To edit a file you have first of all to use the file. To do this from the dot prompt simply type Use . To use the employee file you created for instance you will type Use Employee.
-Select Browse from the Database menu. The highlight moves to the top record. To alter a record simply move the highlight to the record entry you would like to edit and make the appropriate alterations. TO move to the next record press PageDown.
To erase the contents of an entire record simply press CTRL + Y. If you erase a record by mistake you can undo the damage by selecting the undo in the Edit menu.FOXPRO exercise1.You have been asked to design and create a database file to store Information about a Music Library. The music is stored either Cassette tape (CS), Long playing records (LP), or Compact disk (CD) as indicated by the entry. Make an appropriate database and call it task1
On 22nd of February 93 we obtained Greatest Hits by Parache, Milo on an LP costing $8.95 and was classified as Classical. And rest followed up as follows :-
2. Print the Database file and its stru