Sie sind auf Seite 1von 35

Module 2

Database

Introduction
The term database originated within the computing discipline. Although its meaning has been broadened by popular use, even to include non-electronic databases, we concentrate on computer databases.

Definition
A computer database is a structured collection of records or data that is stored in a computer system so that a computer program or person using a query language can consult it to answer queries The records retrieved in answer to queries are information that can be used to make decisions.

Definition
The term database refers to the collection of related records, and the software should be referred to as the database management system or DBMS. When the context is ambiguous, however, many database administrators and programmers use the term database to cover both meanings.

Microsoft Office Access


Microsoft Office Access, previously known as Microsoft Access, is a relational database management system from Microsoft which combines the relational Microsoft Jet Database Engine with a graphical user interface and software development tools. It is a member of the 2007 Microsoft Office system

Use of Access
Skilled software developers and data architects use it to develop application software. Relatively unskilled programmers and non-programmer "power users" can use it to build simple applications. It supports some object-oriented techniques but falls short of being a fully object-oriented development tool

Uses
Access is used by small businesses, within departments of large corporations, and by hobby programmers to create ad hoc customized desktop systems for handling the creation and manipulation of data. Access can be used as a database for basic web based applications hosted on Microsoft's Internet Information Services and utilizing Microsoft Active Server Pages ASP

Prime benefit
One of the benefits of Access from a programmer's perspective is its relative compatibility with SQL (structured query language)
 Queries may be viewed and edited as SQL statements

File extensions
Microsoft Access saves information under the following file extensions:
          
.mdb - Access Database (2003 and earlier) .mde - Protected Access Database, with compiled macros (2003 and earlier) .accdb - Access Database (2007) .accde - Protected Access Database, with compiled macros (2007) .mam - Access Macro .maq - Access Query .mar - Access Report .mat - Access Table .maf - Access Form .adp - Access Project .adn - Access Blank Project Template

Getting started
First of all you need to understand how Microsoft Access breaks down a database. Some keywords involved in this process are: Database File, Table, Record, Field, Data-type

Database and Tables


Database File: This is your main file that encompasses the entire database and that is saved to your hard-drive or floppy disk. Example) StudentDatabase.mdb Table: A table is a collection of data about a specific topic. There can be multiple tables in a database. Example #1) Students Example #2) Teachers

Field and Datatypes


Field: Fields are the different categories within a Table. Tables usually contain multiple fields. Example #1) Student LastName Example #2) Student FirstName Datatypes: Datatypes are the properties of each field. A field only has 1 datatype. FieldName) Student LastName Datatype) Text

Example of a database structure


STUDENT database structure
Field name Code Name Date-of-Birth Address line-1 Address line-2 Address line-3 Address line-4 Marks-English Marks-Hindi Marks-Physics Marks-Chemistry Marks-Maths Numeric String Date String String String String Numeric Numeric Numeric Numeric Numeric 20 20 20 20 3 3 3 3 3 Type Length 4 20

Creating a database

Creating a database
When Microsoft Access first starts up, a dialog box is automatically displayed with options to create a new database or open an existing one. If this dialog box is displayed, click Blank Access Database, and then click OK. If you have already opened a database or closed the dialog box that displays when Microsoft Access starts up, click New Database on the toolbar, and then double-click the Blank Database icon on the General tab. Specify a name and location for the database and click Create.

Create a database without using the Database Wizard

Example of a table

Double-Click on "Create table in Design view". You get this Design View

Defining fields
Define each of the fields in your table. Under the Field Name column, enter the categories of your table. Under Data Type column, enter the type you want for you categories. Under the Description column, enter the text that describes what your field is. (This field is optional).

Data type
 It is the attribute of a variable or field that determines what kind of data it can hold.  For example, in a Microsoft Access database, the Text and Memo field data types allow the field to store either text or numbers, but the Number data type will allow the field to store numbers only.  Number data type fields store numerical data that will be used in mathematical calculations.  Use the Currency data type to display or calculate currency values.  Other data types are Date/Time, Yes/No, Auto Number, and OLE object (Picture).

For our tutorial enter the following items:

Primary key
Keys are one or more fields (columns) whose value or values uniquely identify each record in a table. A primary key does not allow Null values and must always have a unique value. A primary key is used to relate a table to foreign keys in other tables. In the above example, make the Soc Sec # field the primary key, meaning that every student has a social security number and no 2 are the same. To do this, simply select the Soc Sec # field and select the primary key button After you do this, Save the table

Now, enter the data


Click on the Datasheet View and simply start entering the data into each field.

Manipulating Data
Adding a new row
 Simply drop down to a new line and enter the information

Updating a record
 Simply select the record and field you want to update, and change its data with what you want

Deleting a record
 Simply select the entire row and hit the Delete Key on the keyboard

Form design
A Form is nothing more than a graphical representation of a table. You can add, update, delete records in your table by using a form. Although a form can be named different from a table, they both still manipulate the same information and the same exact data. Hence, if you change a record in a form, it will be changed in the table also. A form is very good to use when you have numerous fields in a table. This way you can see all the fields in one screen, whereas if you were in the table view (datasheet) you would have to keep scrolling to get the field you desire.

Form Wizard
It is a very good idea to create a form using the wizard, unless you are an advanced user and know what you are doing. Microsoft Access does a very good job of creating a form using the wizard.

Create a Form
The following steps are needed to create a basic form: Switch to the Database Window. You can do this by pressing F11 on the keyboard. Click on the Forms button under Objects on the left side of screen Double click on Create Form Using Wizard On the next screen select the fields you want to view on your form. Most of the time you would select all of them. Click Next (Contd in the next page)

Create a Form (Contd)


Select the layout you wish Click Next Select the style you desire...HINT: if you plan on printing your form, I suggest you use a light background to save on printer toner and ink Click Next Give your form a name, and select Open the Form and enter information Select Finish You should see your form. To adjust the design of your form, simply hit the design button (same as with the tables), and adjust your form accordingly

Report
A report is an effective way to present your data in a printed format. Because you have control over the size and appearance of everything on a report, you can display the information the way you want to see it.

Create a Report
As with the Form, it is a very good idea to create a report using the wizard, unless you are an advanced user. Microsoft Access does a very good job using the wizard to create reports. Switch to the Database Window. You can do this by pressing F11 on the keyboard. Click on the Reports button under Objects on the left side of screen Double click on Create Report Using Wizard On the next screen select the fields you want to view on your form. Most of the time you would select all of them. Click Next (Contd in the next page)

Create a Report (Contd)


Select if you would like to group your files. Keep repeating this step for as many groupings as you would like. Click Next Select the layout and the paper orientation you desire Click Next Select the style you desire...HINT: if you plan on printing your report, I suggest you use a light background to save on printer toner and ink Click Next Give you report a name, and select Preview the Report Select Finish You should see your report. To adjust the design of your report, simply hit the design button (same as with the tables), and adjust your report accordingly

Basic queries using SQL


In Microsoft Access you can use queries to extract information (data) from one (or more) tables (or from other queries). The information you retrieve can be limited by the definition of your query.

A typical SQL statement


A typical SQL statement resembles the following:
 SELECT DeptCode, CrsNum, Title FROM Courses WHERE DeptCode = COMM;  There are four parts to this statement:
1. SELECT <field1, field2, , fieldn> specifies which fields to project 2. FROM <table> specifies the underlying table (or tables) for the query;

A typical SQL statement (Contd)


 3. WHERE <condition1 AND/OR condition2, , AND/OR conditionn> specifies one or more conditions that each record must satisfy in order to be included in the results set;  4. ; (semicolon) all SQL statements must end with a semicolon (but if you forget it, Access will add it for you).

Run a query

Das könnte Ihnen auch gefallen