31
QUESTION/DISCUSSION 1.How to create a table 1.Understanding Tables A table is a set of columns and rows. Each column is called a field. Within a table, each field must be given a name and no two fields can have the same name. Each value in a field represents a single category of data. For example, a table might have three fields: Last Name, First Name, and Phone Number. The table consists of three columns: one for last name, one for first name, and one for phone number. In every row of the table, the Last Name field contains the last name, the First Name field contains the first name, and the Phone Number field contains the phone number. Each row in a table is called a record. All of the data in a table should refer to the same subject. For example, all of the data in the Employees table should refer to employees, all of the data in the Students table should refer to students, and all of the data in the Courses table should refer to courses. You can view an Access database as a collection of related tables. For example, in a database that contains tables for Employees, Students, and Courses, the Employees table lists the employees, the Students table lists students, and the Courses table lists the courses students can take. After Access creates a blank database, it opens in Datasheet view and makes available the tools you need to create a table. Datasheet view

Assignment Access (Nizammudin Muhammed Pauzi)

Embed Size (px)

DESCRIPTION

ASSIGNMENT ACCESS

Citation preview

QUESTION/DISCUSSION1.How to create a table1.Understanding TablesA table is a set of columns and rows. Each column is called a field. Within a table, each field must be given a name and no two fields can have the same name. Each value in a field represents a single category of data. For example, a table might have three fields: Last Name, First Name, and Phone Number. The table consists of three columns: one for last name, one for first name, and one for phone number. In every row of the table, the Last Name field contains the last name, the First Name field contains the first name, and the Phone Number field contains the phone number. Each row in a table is called a record.

All of the data in a table should refer to the same subject. For example, all of the data in the Employees table should refer to employees, all of the data in the Students table should refer to students, and all of the data in the Courses table should refer to courses.You can view an Access database as a collection of related tables. For example, in a database that contains tables for Employees, Students, and Courses, the Employees table lists the employees, the Students table lists students, and the Courses table lists the courses students can take.After Access creates a blank database, it opens in Datasheet view and makes available the tools you need to create a table. Datasheet view displays a table as a set of columns and rows. When you view a blank database for the first time in Datasheet view, you see a column named ID. This column is by default the primary key field.

Aprimary keyis a field or combination of fields that uniquely identify each record in a table. No two records in a table should have the same values in every field. For example, the following should not occur in a table.Last NameFirst NameCity

SmithJohnJonestown

SmithJohnJonestown

In the real world, it is possible to have two people from the same city with the same first and last name. In cases like this, you can use the ID field as the primary key field and use it to make each record unique. The ID field has a data type of AutoNumber; as a result, Access automatically creates a unique number for each record in the database. The resulting table will look like the one shown here.IDLast NameFirst NameCity

1SmithJohnJonestown

2SmithJohnJonestown

Access provides several methods for creating a table. One method is to use the Rename option with the Add New Field column labelto give each column the field name you want it to have and then to type or paste your data into the table. Field names can include letters, numbers, and spaces and can be up to 64 characters long. When choosing a field name, try to keep it short.When you save your table for the first time, Access gives you the opportunity to name your table. Each table name must be unique; hence, two tables in the same database cannot have the same name. The table name should describe the data in the table; can consist of letters, numbers, and spaces; and can be up to 64 characters long. When choosing a table name, try to keep it short.You can save a table by clicking the Save button on the Quick Access toolbar or by right-clicking the Tables tab and then choosing Save from the menu that appears.

2.To add fields to a table:

1. Click the Add New Field column label.2. Activate the Datasheet tab.3. Click Rename in the Fields & Columns group.4. Type the field name.5. Press Enter. Access creates the field.6. Type the next field name. Access creates the field. Continue until you have created all of the fields in your table.7. Press Enter without entering a field name to end your entries.Or1. Right-click the Add New Field column label. A menu appears.2. Click Rename Column.3. Type the field name.4. Press Enter. Access creates the field.5. Type the next field name. Access creates the field. Continue until you have created all of the fields in your table.

3.Name and Save a TableAfter you create a table, you must name and save it.To name and save a table:

1. Click the Save button on the Quick Access toolbar. The Save As dialog box appears.Type the name you want to give your table.2. Click OK. Access names your table.

4.To use Design view to create a new table:

1. Activate the Create tab.2. Click Table Design in the Tables group. Access changes to Design view and the Table Tools become available.

3. Type the first field name in the Field Name field.4. Press the Tab key.5. Click the down-arrow that appears when you click in the Data Type field and then select a data type.6. Click Primary Key if the column you created is a primary key. A small key appears next to the field name.7. Press the Tab key.8. Type a description. The description is optional.9. Press the Tab key. Access moves to the Field Name field.10. Repeat steps 3 through 10 until you have created all of your fields.

5.To use the Lookup Wizard to create a lookup column:Open the Lookup Wizard

1. Open the table to which you want to add a lookup column.2. Click the field label for the field before which you want to add a lookup column.3. Activate the Datasheet tab. (You must be in Datasheet view.)4. Click the Lookup Column button in the Fields & Columns group. The Lookup Wizard appears.5. Make sure the radio button next to I want the lookup column to look up the values in a table or query. is selected.6. Click Next. The Lookup Wizard moves to the next page.

2.How to create a Query1.How are queries used ?Queries are far more powerful than the simple searches or filters you might use to find data within a table. This is because queries can draw their information frommultipletables. For example, while you could use asearchin the customers table to find the name of one customer at your business or afilteron the orders table to view only orders placed within the past week, neither would let you view both customers and orders at once. However, you could easily run aqueryto find the name and phone number of every customer who's made a purchase within the past week. A well-designed query can give information you might not be able to find out just by examining the data in your tables.When you run a query, the results are presented to you in a table, but when you design one you use a different view. This is calledQuery Design view, and it lets you see how your query is put together.

2.To create a simple one-table query:Select theCreatetab on the Ribbon, and locate theQueriesgroup.Click theQuery Designcommand.

Access will switch toQuery Design view. In theShow Tabledialog box that appears, select the table you would like to run a query on. We are running a query about our customers, so we'll select theCustomerstable.

ClickAdd, then clickClose.The selected table will appear as a small window in theObject Relationship pane. In the table window, double-click thefield namesyou would like to include in your query. They will be added to theDesign Gridin the bottom part of the screen.

In our example, we want to mail invitations to customers who live in a certain area, so we'll include theFirstName,Last Name,Street Address,City, andZip Codefields. We aren't planning on calling or emailing our customers, so we don't have to include thePhone NumberorEmailfields.

Set thesearch criteriaby clicking on the cell in theCriteria:row of each field you would like to filter. Typing criteria into more than one field in the Criteria: row will set your query to include only results that meet all criteria. If you want to set multiple criteria but don't need the records shown in your results to meet them all, type the first criteria in the Criteria: row and additional criteria in theor:row and the rows beneath it.

3.For this one-table query, we'll use simple search criteria.We want to find our customers who live in the city ofRaleigh, so in ourCityfield we'll type"Raleigh". Typing "Raleigh" inquotation markswill retrieve all records with anexact matchfor "Raleigh" in the City field.Some customers who live in the suburbs live fairly close by, and we'd like to invite them as well. We'll add their zip code,27513, as another criteria. Because we want to find customers who either live in Raleighorin the 27513 zip code, we'll type "27513" in theor:row of theZip Codefield.

After you have set your criteria,runthe query by clicking theRuncommand on theDesigntab.

The query results will be displayed in the query'sDatasheet View, which looks like a table. If desired,saveyour query by clicking theSavecommand in the Quick Access toolbar. When prompted to name it, type in the desired name, then clickOK.

Now you know how to create the simplest type of query with onlyone table. In the next lesson, you'll learn how to create a query that usesmultiple tables.

3.How to create a Form1.To create a simple one-table query:Select theCreatetab on the Ribbon, and locate theQueriesgroup.Click theQuery Designcommand.

Access will switch toQuery Design view. In theShow Tabledialog box that appears, select the table you would like to run a query on. We are running a query about our customers, so we'll select theCustomerstable.

ClickAdd, then clickClose.The selected table will appear as a small window in theObject Relationship pane. In the table window, double-click thefield namesyou would like to include in your query. They will be added to theDesign Gridin the bottom part of the screen.

In our example, we want to mail invitations to customers who live in a certain area, so we'll include theFirstName,Last Name,Street Address,City, andZip Codefields. We aren't planning on calling or emailing our customers, so we don't have to include thePhone NumberorEmailfields.

Set thesearch criteriaby clicking on the cell in theCriteria:row of each field you would like to filter. Typing criteria into more than one field in the Criteria: row will set your query to include only results that meet all criteria. If you want to set multiple criteria but don't need the records shown in your results to meet them all, type the first criteria in the Criteria: row and additional criteria in theor:row and the rows beneath it.

2.For this one-table query, we'll use simple search criteria.We want to find our customers who live in the city ofRaleigh, so in ourCityfield we'll type"Raleigh". Typing "Raleigh" inquotation markswill retrieve all records with anexact matchfor "Raleigh" in the City field.Some customers who live in the suburbs live fairly close by, and we'd like to invite them as well. We'll add their zip code,27513, as another criteria. Because we want to find customers who either live in Raleighorin the 27513 zip code, we'll type "27513" in theor:row of theZip Codefield.

After you have set your criteria,runthe query by clicking theRuncommand on theDesigntab.

The query results will be displayed in the query'sDatasheet View, which looks like a table. If desired,saveyour query by clicking theSavecommand in the Quick Access toolbar. When prompted to name it, type in the desired name, then clickOK.

Now you know how to create the simplest type of query with onlyone table. In the next lesson, you'll learn how to create a query that usesmultiple tables.

3.To add a field to a form:Select theDesigntab, then locate theToolsgroup on the right side of the Ribbon.Click theAdd Existing Fieldscommand.

TheField Listpane will appear. Double-click the desired field(s).

The field will be added.

You can also use the above procedure to add fields to a totally blank form. Simplycreate a formby clicking theBlank Formcommand on theCreatetab, then follow the above steps to add the desired fields.

4.To add a field from a different table:You can also add fields fromdifferent tablesin your database to the form.From theField Listpane, clickShow All Tables.Click the plus sign+next to the table that contains the field you wish to add, then double-click the desired field.

The new field will be added.

4.How to create a Reports1.To create a report:Reportsgive you the ability to present components of your database in an easy-to-read, printable format. Access lets you create reports from bothtablesandqueries.Open the table or query you would like to use in your report. We want to print a list of cookies we've sold, so we'll open theCookies Soldquery.

Select theCreatetab on the Ribbon. Locate theReportsgroup, then click theReportcommand.

Access will create a new report based on your object.It's likely that some of your data will be located on the other side of thepage break. To fix this,resizeyour fields. Simply select a field, thenclickanddragits edge until the field is the desired size.Repeatwith additional fields until all of your fields fit.

Tosaveyour report, click theSavecommand on theQuick Access toolbar. When prompted, type anamefor your report, then clickOK.

Just like tables and queries, reports can besortedandfiltered. Simplyright-clickthe field you wish to sort or filter, then select the desired option from the menu.2.Deleting fieldsYou might find that your report contains some fields you don't really need to view. For instance, our report contains theZip Codefield, which isn't necessary in a list of orders. Fortunately, you candeletefields in reports without affecting the table or query where you grabbed your data.To delete a field in a report:Click any cell in the field you would like to delete, then press theDeletekey on your keyboard.

The field will be deleted.When you delete a field, be sure to delete its header as well. Simply select the header and press theDeletekey.

3.To print a report:Click the buttons in the interactive below to learn aboutPrint Preview.

From theHometab, click theViewcommand, then selectPrint Previewfrom the drop-down list. Your report will be shown as it will appear on the printed page.

If necessary, modify thepage size,margin width, andpage orientationusing the related commands on the Ribbon.

Click thePrintcommand.

ThePrintdialog box will appear. Set any desired print options, then clickOK.The report will be printed.4.Saving reportsYou can save reports in other formats so they'll be viewable outside of Access. This is calledexportinga file, and it allows you to view and even modify reports in other formats and programs.Access offers options to save your report as anExcel file,textfile,PDF,HTML document, and more. Experiment with the different export options to find the one that best suits your needs.

5.How to create a Relationship One of the advantages of Relational Database Management System such as Access 2010is to easily setup tables and relationships with constraints to make them more tightly followed. One feature is being the ability to create and maintain relationships between tables.1.To start create a relationsip tableTo start off with, Launch Access,create tablesfor defining relationships among them.For Instance, I am using an existing database with tables (primary keys assigned and data types with constraints applied ). Launch Access 2010, navigate toDatabase Toolson new Access ribbon and clickRelationshipsbutton.

2.Make a colomns names in tableAccess will openRelationshipstab withShow TableDialog box. Select tables, queries or both, and hit Add.

You will see selected tables/queries small windows with columns names inRelationships window.Now sit back start pondering over the selected tables to relate them properly. In this example I am using only four tables (AddictiveTips Example, Courses, Lecturer, Mark Sheet).

3.Creating many one relationshipI am now creating one-many-relationship betweenAddictiveTips Example(Student) andCoursestable. Click & hold the primary key ofAddictiveTips Example,drag it and drop overcourse nameinsmall window ofCourses.ImmediatelyEdit Relationshipsdialog window will pop-up. Here you can create new relationship between tables, Specify Join Type, and Enforce Referential Integrity. For demonstration purpose, I am going to ignore all options and hitCreate.

You will see one-many relationship created betweenAddictiveTips Examples IDandcourse code.4.Creating the junction tableIn this case there are two ways of linked products to orders. We can create a junction table with ansurrogateprimary key field, like the ID Autonumber field Access automatically provides.We can also create our owncompositeprimary key that consists of the two foreign key field in the junction table. I will show you both ways and discuss the implications of each solution.Create the junction table using a surrogate keyThe junction table with surrogate primary key will have three fields, including the ID primary key field that Access automatically creates for you. The two non-primary key fields areforeign keys. They will reference the primary keys of the Order and Product tables (or perhaps some other tables in your case).Create a new table and name it something like LeftTable2RightTable. In my example I named it Order2Product. This notation is often chosen for junction tables.Go to thedesign viewof your new table (Readhow to create a table in Access 2010if you need more info on creating tables in design view).Leave the automatically supplied ID primary key field in tact. Add two new fields. In my example I createdorderandproductfields. The order field will reference the primary key of the Order table. The product field will reference the primary key of the Product table.Make sure your fields are of thesame data typeas the primary key fields they will reference.The example below is a finished junction table with some data. The order and product fields are both of theNumbertype, because they both refer to an Autonumber primary key field, which is in fact a Number field that is managed by the database.

5.Create the actual relationshipsThe final steps in creating the many-to-many relationship is creating the actual relationships in the Relationships view. Creating a many-to-many relationship is a matter of creating two one-to-many relationships. Here is how you do it.Open theRelationshipview by going to the Database Tools tab on the ribbon and selecting the Relationships button.

In the Relationships screen, add the three tables you want to create the many-to-many relationship with to the screen. You can do this bydraggingtables from the left onto the screen or by using theShow Tablewindow, which is accessible via the Show Table button on the ribbon.When your tables are on the Relationship screen drag the primary key fields of the entity tables (Order and Product in this example) to their counterparts in the junction table.

When you drag and drop a primary key field onto a field in another table, Access knows you want to create a relationship and it brings up theEdit Relationshipswindow. This is where you create the actual relationship. In order to create a many-to-many relationship you must createtwo one-to-many relationships.

Create a one-to-many relationship between both your entity tables (Product and Order in this example) and the junction table. Select all three integrity options (Note: the integrity options are discussed in the articleCreate a one-to-many relationship in Access).When both one-to-many relationships are created you have really created a many-to-many relationship, because a many-to-many relationship is made of two one-to-many relationships. The end result should look like this: