L E S S O N 7 Creating and maintaining a database Lesson objectives To become familiar with database maintenance, you will: a b c Create a blank database. Move objects from one database to another. Compact a database. Ashbury Training 2005 7-1
Access 2000: Level 1 a Concepts > Creating a database An Access database contains all of the tables, queries, forms, and reports that are related to a particular purpose or topic. There are several ways to create a database. You can create a blank database and then add the database objects later, or you can use the Database Wizard to create the database along with the objects for that type of database. Creating a blank database To create a blank database, use the New Database button on the toolbar. Database names must conform to the Windows file naming rules. Access automatically assigns the.mdb file extension to databases. Using the Database Wizard The Database Wizard enables you to create a database quickly and efficiently; it provides many ready-to-use databases, complete with tables queries, forms, and reports. You can always customize generic database objects to better suit your needs. Task A-1: Creating and naming a blank database q Objective: To create a blank database that will hold objects that have already been created. What you do 1. Click on the New button Comments/Prompts 2. Select the Databases tab To display the New dialog box. Observe the icons Each icon represents a type of database that you can create. Selecting an icon prompts the Database Wizard to create, in one operation, all the tables, forms, reports, and data access pages for the selected type of database. 7-2 Ashbury Training 2005
Lesson 7: Creating and maintaining a database 3. Select the General tab Select the Database icon Click on OK To create a blank database. To display the File New Database dialog box. This is where you can specify a name and location for the new database. This dialog box, like the Open and Save As dialog boxes, also includes the Places Bar so that you can easily navigate among the places where you might store this database. 4. In the File Name text box, type MyNewDb Click on Create Access creates the database. 5. If necessary, maximize the Database window Observe the Database window The MyNewDb database is open. After you create a blank database, you must perform additional steps to define the objects that will make up the database. Ashbury Training 2005 7-3
Access 2000: Level 1 b Managing a database and its objects Working with an entire database Concepts > If you want to rename, copy, delete, or move an entire database, you can do so by using Windows Explorer. Windows Explorer enables you to browse and manage resources. You can use the Windows Explorer to view the folders containing your Access databases. Objects are organized in a hierarchical tree-like structure, with the desktop as the highest container object. Access database files have an extension of.mdb. When using Windows Explorer to view the Access databases, you do not see a list of objects that make up the database you see just the database. Therefore, you cannot copy Access objects from one database to another by using the Windows Explorer. Working with individual database objects Because Access objects reside in a database file, you must use Access to copy, delete, and rename objects. There are several ways to work with individual objects. The Database window and the Clipboard When you work in the Database window, the Clipboard is available so that you can cut or copy objects and paste them in a new location. For instance, with a table selected, you can choose either the Cut or Copy button from the Database toolbar. If you are moving or copying the table to a different database, close the current database and open the database into which you want to paste the object. When you work within the Database window, you can also delete and rename individual database objects. Importing database objects The File, Get External Data, Import and the File, Get External Data, Link Tables commands are usually the most efficient way to copy Access objects. You can also use these commands to import or export objects to and from other software applications as well as between Access databases. Task B-1: Importing an object q Objective: To copy a table from the Copy database to the MyNewDb database. What you do Comments/Prompts 1. In the Database window, ensure that the list of table objects is displayed 2. Choose _File Get_External_Data Import..._ To display the Import dialog box. 7-4 Ashbury Training 2005
Lesson 7: Creating and maintaining a database 3. Select the database Copy Click on Import To display the Import Objects dialog box. 4. Select the tblhumanresourcesdata table Click on OK 5. Observe the Database window To select the table to import to the MyNewDb database. To import the table. The MyNewDb database now contains the tblhumanresourcesdata table. Practice Task Import the tblpersonaldata table from the Copy database into the MyNewDb database. Concepts > Importing multiple objects Access enables you to import more than one object at a time. Each object must be selected in the Import dialog box. Ashbury Training 2005 7-5
Access 2000: Level 1 Task B-2: Importing more than one object ü Before you begin: Complete the Practice Task at the end of Task B-1. What you do Comments/Prompts 1. Choose _File Get_External_Data Import..._ Select the database Copy Click on Import 2. Select the tbldepartment table Hold down S Select the tblparkinginfo table Release S Two tables are selected. 3. Select the Queries tab Click on Select All To select the two queries to be imported. 4. Select the Forms tab Select the frmphonedata form 5. Select the Reports tab Select the rptparkinglot report 6. Click on OK To import all the objects. 7. In the MyNewDb Database window, view the objects 8. Close the Database window 7-6 Ashbury Training 2005
Lesson 7: Creating and maintaining a database c Concepts > Database maintenance Once you create and start using your database, you will probably need to perform some maintenance tasks to help protect it and keep it up-to-date. Backing up a database A very important administrative task in maintaining a database is creating a backup of the database. Backup copies protect you against losing critical data. Since Access stores all database information in one file, backing up a database is not a complicated procedure. You can use the Windows Explorer, My Computer, the MS-DOS Copy command, or backup software to copy the database file (an.mdb file) to the backup medium of your choice. Converting a database Because Access has been around for many years, many databases have been created using this program. If you attempt to open a database created in a previous version of Access, you will be prompted to either convert the database or open the database. If you convert the database, Access creates a brand new file from the old version; however, you will not be able to use the database with previous versions of Access. If you opt to open the database instead of converting it, you will still be able to use the database with previous versions of Access but you can only view the database objects; you will be unable to change the design of any objects. Likewise, you can convert a database file to a prior version of Access by using the Tools, Database Utilities, Convert Database command. Compacting a database Compacting a database helps it to run more efficiently and take up less storage space. When you delete tables or records, the database can use disk space inefficiently, because hard disk space within the database remains unused. This is called fragmentation. To reclaim the unused hard disk space, you can compact your database. This makes a copy of the database, rearranging how the database file is stored on disk. You can use the same database name or specify a new name. Repairing a database In most cases, Access will detect that a database is damaged when you try to open, compact, encrypt, or decrypt it. At that time, it will give you the option to repair the database. However, in some cases, Access might not detect that a database is damaged. If a database behaves unpredictably, you can manually repair the current database by using the Tools, Database Utilities, Compact And Repair command. If you want to specify a new name or location for the database, close the current database and then issue the command. Ashbury Training 2005 7-7
Access 2000: Level 1 Task C-1: Deleting a table and compacting a database What you do 1. Open the Maint database If necessary, maximize the Database window Comments/Prompts You can have only one database open at a time. But within a database, you can have multiple objects open. 2. Select the tblhumanresourcesdata table 3. Press D Click on Yes 4. Close the Database window In the alert box, you are asked to confirm that you want to delete the table. As you add and delete objects in a database file, the file can become fragmented and inefficient. 5. Choose _Tools Database_Utilities Compact_And_Repair_Database _ Compacting a database eliminates fragmentation and improves performance. 6. Select Maint Click on Compact To select a database you want to compact. 7. In the File Name text box, type MyMaint Click on Save To enter a filename for the compacted database. You can specify a new name for the compacted database or use the same name. Access makes a copy of the database. 8. Click on the Close button To exit Access 2000. 7-8 Ashbury Training 2005
Lesson 7: Creating and maintaining a database Concepts > Exiting Access When you exit Access by choosing File, Exit or by clicking on the Close button in the application window, Access automatically saves any unsaved changes to data. If you have changed other Access objects, then you will be prompted to save those changes before you exit. You should always use one of these methods to exit Access to ensure that all of your work is saved. Ashbury Training 2005 7-9
Access 2000: Level 1 ) Wrap-up for Lesson 7 a Why would you create a new database? Which file extension is automatically assigned to databases in Access? b Why might you want to copy objects from one database to another? c Why would you compact a database? 7-10 Ashbury Training 2005