02-DBBA Marek Kręglewski

Transcription

Databases for beginners02-DBBAMarek Kręglewski1

About the course Steven Roman, Access Database Design &Programming (3rd Edition), O’Reilly 2002 Curtis D. Frye, Microsoft Office Access 2007Plain & Simple, Microsoft Press 2007 http://office.microsoft.com/en-us/access-help/# ase-basicsHA010064450.aspx#BMpartsofadatabase2

Basics about a database? A database is a structured collection of records. Database Management System (DBMS)––––add, remove, update recordsretrieve data that match certain criteriacross-reference data in different tablesperform complex aggregate calculation Database consists of columns (attributes) and rows(records). Databases versus spreadsheets– easy manipulation of data3

Single table Price0-99-999999-9Emma1Austen111-111-11111Big House123-456-789020.00 zł0-91-335678-7Faerie Queen7Spenser777-777-77771Big House123-456-789017.00 ha Press999-999-999920.00 zł0-103-45678-9Iliad3Homer333-333-33331Big House123-456-789025.00 pha Press999-999-999912.00 zł0-55-123456-9Main Street10Jones123-333-33333Small House714-000-000023.00 zł0-55-123456-9Main Street9Smith123-222-22223Small House714-000-000023.00 zł0-12-333433-3On Liberty8Mill888-888-88881Big House123-456-789025.00 zł0-321-32132-1Balloon2Sleepy222-222-22223Small House714-000-000034.00 zł0-321-32132-1Balloon4Snoopy444-444-44443Small House714-000-000034.00 zł0-321-32132-1Balloon11Grumpy321-321-00003Small House714-000-000034.00 zł4

Disadvantages of a single table database Redundancy of dataProblem with complex dataProblems in updating in bulk (new phone number)Problems in adding incomplete data (new publisher)Problems in removing group of data (all books from thepublisher)Solution:Relational Database Management System (RDBMS) E.g. Microsoft Access5

Relational Database System of related tablesMinimum redundancyReferential integrityDatabase keysThe ACID model (guarantee of successful transactions):––––Atomicity („all or nothing” rule)Consistency (only valid data in)Isolation (order of executed transactions)Durability (committed transaction will not be lost)6

Relations in a databaseexampleAuNameTitlePriceISBNBooks AuIDWritten by ed byPubIDAuTelCoauIDCoauTelCoauName7

Home library – table BooksISBNTitlePubIDPrice0-103-45678-9Iliad125.00 zł0-11-345678-9Moby Dick349.00 zł0-12-333433-3On Liberty125.00 zł0-123-45678-0Ulysses234.00 zł0-12-345678-9Jane Eyre349.00 zł0-321-32132-1Balloon334.00 zł0-55-123456-9Main Street323.00 zł0-555-55555-9Macbeth212.00 zł0-91-045678-5Hamlet220.00 zł0-91-335678-7Faerie Queen115.00 zł0-99-777777-7King Lear249.00 zł0-99-999999-9Emma120.00 zł1-1111-1111-1C 130.00 zł1-22-233700-0Visual Basic125.00 zł8

Home library – table 000013Sleepy321-321-11119

Home library – table PublishersPubIDPubNamePubTel1Big House123-456-78902Alpha Press999-999-99993Small House714-000-000010

Home library – table -22-233700-0411

Table Unique nameSize # of rows, order # of columnsStructure of a table T{ A1, A2, , An }All rows differentOrder of rows not importantUnique headers identify columnsNULL value in tables12

Database keys Primary key– Value unique for each record in a table– This value can not be used twice– AutoNumber guarantees uniqueness but does not carry anyuseful information Foreign keys– Used to create relationships between tables– No uniqueness constraint for foreign keys Relation between primary and foreign keys– Same format– Same values13

Relations in a databaseexampleAuNameTitlePriceISBNBooks AuIDWritten by ed byPubIDAuTelCoauIDCoauTelCoauName14

Building relationsRelation one-to-oneTable SA1A2A3Table TA4A5A1B1B2B3B415

Building relationsRelation one-to-manyTable SA1A2A3Table TA4A5A1PrimaryForeignkeykeyB1B2B3B4Values of the foreign key can not be different from the values of the primary key.16

Building relationsRelation many-to-manyTable SA1Table S/TA2A3A4A5A1Table TB1B1B2B3B417

Enforcing referential integrity Cascade Update Related Fields – thevalues of foreign keys change followingchanges of the values of the primary key Cascade Delete Related Records –deleting a record from the primary field ina relationship causes a deletion of allrelated records in the second table18

Indexing field values Purpose: speed up access to specific dataUsed in large tablesUpdating of all indexes every time a table record is updatedor addedExampleIndex of townsTable of shopsGdańsk 1PlusToruńKraków 2PiotrPoznańPoznań 3TescoKrakówPoznań 4TescoPoznańToruń 5PlusGdańsk19

Principles for building a database Types of attributes:– Identification– Information– Identification information Example 1: {PubID,PubName,PubTel,FoundYear}IdentIdent eth1Big House Example 2:2-2222-2222-2 Hamlet15-5555-5555-52ABC Press20

Queries Database – data located in tables relations Query – primary mechanism for retrieving informationfrom a database, consists of questions presented to thedatabase in a predefined format – an expression storedin a database having a unique name Answer to the query – a computed table Dynaset SQL – Structured Query Language Types of queries:– Select query– Action queries (Make-Table, Append, Update, Delete)– Crosstab query21

Creating a query in MS Access22

Design View of a queryDrug and drop principle23

Selection criteria Specifying criteria:––––A value of an expressionUse of criteria operators: , , , , BETWEEN, e.g. BETWEEN 2 AND 5,LIKE, e.g. LIKE „*[b-d]k[0-5]?#” Logical operators: OR, AND– e.g. „Smith” OR „Jones” Mathematical operators: , - ,*, /, \, MOD, Text operator:& Date/Time fields– Format #2009-06-19##16:00##4:00PM#– Date/time functions: Date()Day(date), Month(date), Year(date), Weekday(date)24

Calculation on groups of records25

Parameter queryWhen you run the query, you will be prompted to supply the maximum price26

Crosstab query27

Database Normalization Basics Purpose: - eliminating redundant data- ensuring logical relations of dependent data The normal forms- 1NF, 2NF, 3NF, BCNF- guidelines only- hierarchical structure of NF First Normal Form (1NF)- eliminate duplicative columns- create separate tables for each group of related dataand define primary keyse.g. Authors Jones, H.; Smith K. (incorrect)28

Database Normalization Basics Second Normal Form (2NF)- meet all requirements of the 1NF- remove subsets of data that apply to multiple rows andplace them in separate tables- create relationships between new tables using foreignkeys Example - table of addresses:{Town, Street, HouseNumber, HouseColor, SizeOfTown}attribute of Town29

Database Normalization Basics Third Normal Form (3NF)- meet all requirements of the 2NF- remove columns that are not dependent upon primary key Example{ISBN, Title, NumberOfBooks, UnitPrice, TotalValue}where: TotalValue NumberOfBooks*UnitPriceCorrect form:{ISBN, Title, NumberOfBooks, UnitPrice}30

Database Normalization Basics Fourth Normal Form (Boyce-Codd NF BCNF)- meet all requirements of the 3NF- remove all multi-valued dependencies Example{Town, Street, HouseNumber, ZIPcode}where: combination of {Town, Street}determines{Zipcode}Correct form:{Street, HouseNumber, ZIPcode}and {ZIPcode, Town}31

Decomposition of tables Relations between data must be conservedAuIDAuNamePubIDA1Smith, JohnP1A2Smith, JohnP2 DecompositionAuIDAuNameAuNamePubIDA1Smith, JohnSmith, JohnP1A2Smith, JohnSmith, JohnP2 Display all John SmithsAuIDAuNamePubIDA1Smith, JohnP1A1Smith, JohnP2A2Smith, JohnP1A2Smith, JohnP232

Example: Relation ORDERS not normalizedNo g,Rotestrasse 1053Carburetor1005Warszawa,Chopina 357Crankshaft505Warszawa,Chopina 359Mudguard5006Warszawa,Mozarta 2554Carburetor5005Warszawa,Chopina 332Wheel1006Warszawa,Mozarta 25002400WSKŚwidnik,Kraszewskiego 5003500VWPolskaAntoninek,Słowackiego 288Engine157Warszawa,Bacha 3004600FIATBielsko-Biała,Mickiewicza 2558Mudguard4006Warszawa,Mozarta 2521Alternator507Warszawa,Bacha 353Carburetor2005Warszawa,Chopina 357Crankshaft305Warszawa,Chopina 359Mudguard206Warszawa,Mozarta 25005006300300VWVWWolfsburg,Rotestrasse 10Wolfsburg,Rotestrasse 1033

Relation ORDERS in the first normal form (1NF)eliminates duplicative columnsNo g,Rotestrasse 1053Carburetor1005Warszawa,Chopina 3001300VWWolfsburg,Rotestrasse 1057Crankshaft505Warszawa,Chopina 3001300VWWolfsburg,Rotestrasse 1059Mudguard5006Warszawa,Mozarta 25002400WSKŚwidnik,Kraszewskiego 554Carburetor5005Warszawa,Chopina 3002400WSKŚwidnik,Kraszewskiego 532Wheel1006Warszawa,Mozarta 25003500VWAntoninek,Słowackiego 288Engine157Warszawa,Bacha 3004600FIATBielsko-Biała,Mickiewicza 2558Mudguard4006Warszawa,Mozarta 25004600FIATBielsko-Biała,Mickiewicza 2521Alternator507Warszawa,Bacha 3005300VWWolfsburg,Rotestrasse 1053Carburetor2005Warszawa,Chopina 3005300VWWolfsburg,Rotestrasse 1057Crankshaft305Warszawa,Chopina 3006300VWWolfsburg,Rotestrasse 1059Mudguard206Warszawa,Mozarta3425

Relation ORDERS in the second normal form (2NF)all attributes fully dependent on primary keysNo orderIDsupplierName supplierAddress supplierIDpartName partQtyWarehouseDiagram of functionaldependencies in therelation ORDERSAddress warehouse35

No orderIDsupplierNamesupplierAddress Supplier001300VWWolfsburg,Rotestrasse 10002400WSKŚwidnik,Kraszewskiego 5003500VWAntoninek,Słowackiego 2004600FIATBielsko-Biała,Mickiewicza 25005300VWWolfsburg,Rotestrasse 10006300VWWolfsburg,Rotestrasse 10SUPPLIER ON ORDER2NFPARTS ON ORDERNo 100IDpartName partWarehouseAddress Warehouse003881553Carburetor5Warszawa, Chopina 30045840057Crankshaft5Warszawa, Chopina 3004215058Mudguard6Warszawa, Mozarta 250055320059Mudguard6Warszawa, Mozarta 25005573054Carburetor5Warszawa, Chopina 3006592032Wheel6Warszawa, Mozarta 2588Engine7Warszawa, Bacha 321Alternator7Warszawa, Bacha 3PARTS IN WAREHOUSE36

Relation ORDERS in the third normal form (3NF)remove column not dependent upon primary keyNo orderIDsupplierDiagram of functionaldependencies in the relationSUPPLIER ON ORDERName supplierAddress supplierIDpartDiagram of functionaldependencies in the relationPARTS IN WAREHOUSEName partWarehouseAddress warehouseNo orderIDpartQtyDiagram of functionaldependencies in the relationPARTS ON ORDER37

ORDER TO SUPPLIERNo 03NFNo orderIDsupplierSUPPLIERSIDsupplierName SupplierAddress Supplier300VWWolfsburg, Rotestrasse 10400WSKŚwidnik, Kraszewskiego 5500VWAntoninek, Słowackiego 2600FIATBielsko-Biała, Mickiewicza 25IDupplierName supplierAddress SupplierWAREHOUSESWarehouseAddress Warehouse5Warszawa, Chopina 36Warszawa, Mozarta 257Warszawa, Bacha 3WarehouseAddress Warehouse38

PARTSPARTS IN WAREHOUSEPARTS ON ORDERas aboveIDpartName se5355755865965453268872173NFIDpartName partIDpartWarehouse39

Example: ORDERS40

Structured Query Language - SQLWhy to use SQL in addition to the Design View?- not all SQL functions can be used from the Design View level- SQL can be used in other applications (Excel, Word, Visual Basic)- SQL is a standard query language which can be used outside theAccess programOne can easily switch between Design View and SQL ViewSQL is a procedure language which tells what to do, and nothow to do.SQL components:- Data Definition Language – DDL- Data Manipulation Language – DML- Data Control Language - DCL41

DML component of SQLBasic instructions:- SELECT- UPDATE- DELETEBasic structure of the SQL command:SELECT column1, column2, FROM table1, table2, WHERE criteria;List of columns can be replaced with *.42

SortingSELECT PUBLISHERS.PubName, PUBLISHERS.PubTelFROM PUBLISHERSORDER BY PUBLISHERS.PubName;PubNamePubTelAlpha Press999-999-9999Big House123-456-7890Small House714-000-0000orORDER BY attribute DESC43

Changing field namesSELECT PUBLISHERS.PubName AS [Publisher’s Name],PUBLISHERS.PubTel AS [Publisher’s Phone]FROM PUBLISHERSORDER BY PUBLISHERS.PubName;Publisher’s NamePublisher’s PhoneAlpha Press999-999-9999Big House123-456-7890Small House714-000-000044

FilteringSELECT COUNT (ISBN) AS [How many books from Alpha Press?]FROM BOOKSWHERE (PubID 1);How many books from Alpha Press?6SELECT COUNT(ISBN) AS [Number of books],MIN(Price) AS Min Price,MAX(Price) AS Max Price,AVG(Price) AS Avg PriceFROM BOOKS;Number of booksMin PriceMax PriceAvg Price1512.00 zł49.00 zł29.27 zł45

GroupingSELECT PubID, COUNT(*) AS [Number of books]FROM BOOKSGROUP BY PubID;PubIDNumber of books1624344146

Group filteringSELECT PubID, COUNT(*) AS [Number of books]FROM BOOKSGROUP BY PubIDHAVING COUNT(*) 2 ;PubIDNumber of books16243447

Aggregation, filtering,grouping, group filteringSELECT PubID, COUNT(*) AS [Number of books]FROM BOOKSWHERE Price 25GROUP BY PubIDHAVING COUNT(*) 2 ;PubIDNumber of books14223348

Elements of the SELECT commandElementDescriptionCompulsory?SELECTReturns columns or expressionsYesFROMTaking data from tablesYes if data from tablesWHEREFiltering rowsNoGROUP BYCreating groupsYes for aggregationfunctionsHAVINGFiltering groupsNoORDER BYSorting of the outputNo49

DELETE and UPDATEDELETE BOOKS1.PriceFROM BOOKS1WHERE ((BOOKS1.Price) 40);UPDATE BOOKS1SET BOOKS1.Price [BOOKS1]![Price] 1;UPDATE BOOKS1SET BOOKS1.Price [BOOKS1]![Price] 1WHERE ((BOOKS.Price) 20);50

Queries based on multiple tablesSELECT Title, PubName, PriceFROM PUBLISHERS, BOOKSWHERE PUBLISHERS.PubID BOOKS.PubIDORDER BY BOOKS.Title;Design ViewDynaset – a computed table51

Inner join 1SELECT BOOKS.Title, PUBLISHERS.PubName, BOOKS.PriceFROM PUBLISHERS, BOOKSWHERE PUBLISHERS.PubID BOOKS.PubIDORDER BY BOOKS.Title;SELECT BOOKS.Title, PUBLISHERS.PubName, BOOKS.PriceFROM PUBLISHERS INNER JOIN BOOKSON PUBLISHERS.PubID BOOKS.PubIDORDER BY BOOKS.Title;Structure of the inner join one-to-many:TABLE1 INNER JOIN TABLE2ON TABLE1.primarykey TABLE2.foreignkey52

Inner join 2 one-to-manySELECT Count(BOOKS.Title) AS [Number of books],PUBLISHERS.PubName,AVG(BOOKS.Price) AS [Average price]FROM PUBLISHERS INNER JOIN BOOKSON PUBLISHERS.PubID BOOKS.PubIDGROUP BY PUBLISHERS.NameORDER BY PUBLISHERS.Name;53

What happens if WHERE is missing?SELECT BOOKS.Title, PUBLISHERS.PubName, BOOKS.PriceFROM PUBLISHERS, BOOKS;TitlePubNamePriceIliadBig House25.00 złIliadAlpha Press25.00 złIliadSmall House25.00 złIliadEdition 200025.00 złMoby DickBig House49.00 złMoby DickAlpha Press49.00 złMoby DickSmall House49.00 złMoby DickEdition 200049.00 złOn LibertyBig House25.00 złOn LibertyAlpha Press25.00 złOn LibertySmall House25.00 złOn LibertyEdition 200025.00 złUlyssesBig House34.00 złUlyssesAlpha Press34.00 złUlyssesSmall House34.00 złUlyssesEdition 200034.00 zł .Result:A direct productof two tables54

Inner join 3 many-to-manySELECT BOOKS.Title, BOOKS.ISBN, BOOKS.Price, BOOKS.Year,PUBLISHERS.PubName, AUTHORS.AuNameFROM PUBLISHERSINNER JOIN (BOOKSINNER JOIN (AUTHORSINNER JOIN [BOOKS/AUTHORS]ON AUTHORS.AuID [BOOKS/AUTHORS].AuID)ON BOOKS.ISBN [BOOKS/AUTHORS].ISBN)ON PUBLISHERS.PubID 103-45678-925.00 zł1989Big HouseHomerMoby Dick0-11-345678-949.00 zł1998Small HouseMelvilleOn Liberty0-12-333433-325.00 zł1987Big HouseMillUlysses0-123-45678-034.00 zł1999Alpha PressJoyceJane Eyre0-12-345678-949.00 zł1990Small HouseAustenBalloon0-321-32132-134.00 zł1995Small HouseSnoopyBalloon0-321-32132-134.00 zł1995Small HouseGrumpyBalloon0-321-32132-134.00 zł1995Small HouseSleepyMain Street0-55-123456-923.00 zł1996Small HouseSmithMain Street0-55-123456-923.00 zł1996Small HouseJonesMacbeth0-555-55555-912.00 zł1991Alpha PressShakespeareHamlet0-91-045678-520.00 zł2000Alpha PressShakespeare55

Query Customers1SELECT [First name] & " " & [Surname] AS Person,BOOKS.Title, [CUST/BOOKS].DateOut, [CUST/BOOKS].DateBackFROM CUSTOMERINNER JOIN (BOOKSINNER JOIN [CUST/BOOKS]ON BOOKS.ISBN [CUST/BOOKS].ISBN)ON CUSTOMER.CustID [CUST/BOOKS].CustID;56

Query Customers2 – OUTER JOINSELECT CUSTOMER!First name & " " & CUSTOMER!Surname AS Person,WhoBorrowsID.Title, WhoBorrowsID.DateOut, WhoBorrowsID.DateBackFROM CUSTOMER LEFT {outer} JOIN WhoBorrowsIDON CUSTOMER.CustID WhoBorrowsID.CustID;WhoBorrows is a query57

Query WhoBorrowsSELECT [CUST/BOOKS].CustID, BOOKS.Title, [CUST/BOOKS].DateOut,[CUST/BOOKS].DateBackFROM BOOKS INNER JOIN [CUST/BOOKS]ON BOOKS.ISBN [CUST/BOOKS].ISBN;58

NULL in a querySELECT BOOKS.ISBN, BOOKS.Title, [CUST/BOOKS].DateOut,[CUST/BOOKS].DateBackFROM BOOKSLEFT JOIN [CUST/BOOKS] ON BOOKS.ISBN [CUST/BOOKS].ISBNWHERE((([CUST/BOOKS].DateOut) Is Null) AND (([CUST/BOOKS].DateBack) Is Null)) OR((([CUST/BOOKS].DateOut) Is Not Null) AND (([CUST/BOOKS].DateBack) Is Not Null))ORDER BY BOOKS.Title;Available books59

Functional queriesSELECT CUSTOMER!Surname & " " & CUSTOMER!First name AS Person,Count([CUST/BOOKS].ISBN) AS [Number of books],Year([CUST/BOOKS]!DateOut) AS YearOutINTO Table NotReturnedFROM CUSTOMER INNER JOIN [CUST/BOOKS]ON CUSTOMER.CustID [CUST/BOOKS].CustIDGROUP BY CUSTOMER!Surname & " " & CUSTOMER!First name,Year([CUST/BOOKS]!DateOut), [CUST/BOOKS].DateBackHAVING ((([CUST/BOOKS].DateBack) Is Null) AND((Year([CUST/BOOKS]!DateOut)) [Give the year]))ORDER BY CUSTOMER!Surname & " " & CUSTOMER!First name;Only SELECTCreating a new table60

Functional queriesCreating o copy of a tableSELECT *INTO NotReturned2008FROM Table NotReturned;Merging two tablesINSERT INTO Table NotReturnedSELECT *FROM NotReturned2008;61

Creating reportsCharacteristic features of a report: attractive form basic information in headers and footers information grouped and sorted graphical elements improving the formMethods of creating reports: design view Wizard AutoReport: Columnar or TabelarSource of data: tables or queries62

AutoReport63

Report – design view64

ToolboxCombo boxText boxList boxLabelSubreportImageButton65

Database formA form is an Access object. It generally serves three purposes:1) To allow users to perform data entry. Data can be inserted, updated,or deleted from a table using a Form object.2) To allow users to enter custom information, and based on thatinformation perform a task. For example, you may want to ask a userfor parameters before running a report.3) To allow users a method of navigating through the system. Forexample, you may create a form where a user can select a form toload, a report to run, etc.Forms: bound or unboundA bound form has a RecordSource, a table or query to which the form is"tied" or "based". An unbound form does not have a RecordSource,that doesn't mean it can't contain data, but the programmer will haveto bring that data in manually.66

Creating Forms in Microsoft AccessRemember: there is a largenumber of pre-defined forms.The Form options quicklycreate a form based upon atable or query.67

Form Design68

Creating forms – Form WizzardForm facilitating introduction of a new customer to the database:1) Select the datasource2) Select the formfields69

Creating forms – the layout and style70

Creating forms – the form titleThe form can bemodified in DesignView mode.71

Creating forms - adjustments72

Using a formAccess to the existing records inthe table CUSTOMERInput of a new record73

Editing properties of a formProperties icon:Our original goal is to create a form for data purposes. Wedon’t want to grant employees full access to view or editcustomer records. Setting the „Data Entry” property to„Yes” will only allow users to insert new records and modifyrecords created during that session.74

The form after the edition of propertiesOpening the form: no earlierrecords can be seenThe CustID is automaticallyassigned, First name andSurname are typed in.A new record is introducedinto the table CUSTOMER:75

Security differences between Access2007 and earlier versions of AccessEarlier versions:-security levels (Low, Medium, or High),-to run potentially unsafe code or not.Access 2007 disables all potentially unsafe code or othercomponents, regardless of the version of Access that you usedto create the database.Message Bar:You can choose to trust or not trust the disabledcontent in the database.76

You trust the disabled content: Trust the database only for the current session (while thedatabase is open) Click Options on the Message Bar. Trust the database permanently Place the database in a trustedlocation — a folder on a drive or network that you mark as trusted.You don't trust the database:Ignore the Message Bar. When you ignore the Message Bar, youcan still view the data in the database and use any componentsin the database that Access has not disabled.77

Trust a database for the current session1. Start Office Access 2007, and on the Getting Started withMicrosoft Office Access page, under Featured OnlineTemplates, click Assets to open the Assets template.78

2. In the File Name box, type a name for the new database, andthen click Download. Access downloads the database templateand creates a new database, and the Message Bar appears.3. On the Message Bar, click Options. The Microsoft OfficeSecurity Options dialog box appears.4. Click Enable this content, and then click OK.79

Create a trusted locationStart Office Access 2007 (you do not need to open a database tocomplete these steps).Click the Microsoft Office Button, and then click AccessOptions.Click Trust Center, and then click Trust Center Settings.80

Click Trusted Locations.Click Add new location.The Microsoft Office Trusted Location dialog box appears.81

The Microsoft Office Trusted Location dialog box appears.In the Path box, type the file path and folder name of the location thatyou want to set as a trusted source, or click Browse to locate a folder.By default, the folder must reside on a local drive.Note If you want to allow trusted network locations, in the TrustCenter dialog box, click Allow Trusted Locations on my network(not recommended).82

Move a database to a trusted locationIf you have a database openClick the Microsoft Office Button .Point to Save As, and under Save the database in anotherformat, click one of the available options.In the Save As dialog box, navigate to the trusted location,and then click Save.If you do not have a database openLocate and copy your database83

Use a database password to encrypt anOffice Access 2007 databaseThe encryption tool in Office Access 2007 combines and improveson two older tools — database passwords and encoding.Open in exclusivemode84

Encrypt by using a database passwordOpen the database (in Exclusive mode) that you want to encrypt.On the Database Tools tab, in the Database Tools group, clickEncrypt with Password. The Set Database Password dialogbox appears.85

Decrypt and open a database1. Open the encrypted database as you open any otherdatabase.2. The Password Required dialog box appears.3. Type your password in the Enter database password box,and then click OK.86

Remove a passwordOpen the database in Exclusive mode.On the Database Tools tab, in the Database Tools group, clickDecrypt Database.87

Package, sign, and distributean Access 2007 databaseAccess 2007 makes it easier and faster to sign and distribute adatabase. When you create an .accdb file or .accde file, you canpackage the file, apply a digital signature to the package, and thendistribute the signed package to other users. ways to convey trust add only one database to a package signs all of the objects in your databases the process also compresses the package file a security certificate88

Create a self-signed certificateIn Microsoft Windows, click the Start button, point to AllPrograms, point to Microsoft Office, point to Microsoft OfficeTools, and then click Digital Certificate for VBA Projects89

Create a self-signed certificate90

Create a self-signed certificate91

Create a signed packageOpen the databaseMicrosoft Office Button ,point to Publish, and thenclick Package and SignSelect a digital certificate andthen click OKThe Create Microsoft OfficeAccess Signed Packagedialog box appears92

Create a signed packageSelect a location for your signeddatabase package.Enter a name for the signedpackage in the File name box,and then click Create.Access creates the .accdc fileand places it in the location thatyou choose93

Extract and use a signed package1.Click the Microsoft Office Button , and then click Open.2.Select Microsoft Office Access Signed Packages (*.accdc) asthe file type.3.Locate the folder that contains your .accdc file, select the file, andthen click Open.4.Do one of the following: If you have earlier chosen to trust the digital certificate thatwas applied to the deployment package, the ExtractDatabase To dialog box appears. Go to the next step. If you have not yet chosen to trust the digital certificate, anadvisory message appears.94

Extract and use a signed packageIf you trust the database, clickOpen. If you trust any certificatefrom that provider, click Trust allfrom publisher and then clickOK.Optionally, select a location for the extracted database, andthen in the File name box, enter a different name for theextracted database95

Splitting a database96

Hide VBA code from usersIf your database contains Visual Basic for Applications (VBA) (Visual Basicfor Applications (VBA): A macro-language version of Microsoft Visual Basicthat is used to program Windows applications and is included with severalMicrosoft applications.) code, you can hide that code by saving yourMicrosoft Office Access database (database: A collection of data related toa particular subject or purpose. Within a database, information about aparticular entity, such as an employee or order, is categorized into tables,records, and fields.) in the .accde file format. Saving a database as an.accde file compiles all VBA code modules, removes all editable sourcecode, and compacts the destination database. Your VBA code retains itsfunctionality, but the code cannot be viewed or edited. In general, thedatabase will continue to function as usual — you can still update data andrun reports.97

Microsoft Access SecurityThe Security Wizard in MS Access is a very useful tool.But there is more to security than just running the wizard.The 12 steps will describe how to secure a databasefrom start to finish.98

How to secure a database?1. You may secure any database that has been created while joined to theSystem.Mdw.2. Create a new workgroup file(*. MDW)3. Open the unsecured database and create a password for the Admin user.4. Create a new user account that will be the new workgroup administrator, like"PowerAdmin"5. Modify the Admins group by adding the new administrator and removing theoriginal Admin account.6. Re-log into Access as the new workgroup administrator that you createdpreviously.7. Set up a password for the new workgroup administrator.8. Run the Security wizard under Tools Security User - Level Security.9. Create any additional group accounts.10. Create any additional user accounts.11. Set up the database object's permissions.12. Any new databases that you create will already be secure.99

System.MDW fileA Workgroup Information File (*.MDW) storesinformation to authenticate a user. It stores the usernames, group names, and passwords. It does notstore any permission or rights to any database. Itsmain purpose is to verify that a user is really whothey say they are. The permissions of the databaseobjects, tables, queries, forms, etc., are stored ineach MDB file. The System.mdw is the defaultworkgroup filename created when you install MSAccess.100

The Admin userEvery time a user opens the MS Access program, MSAccess attempts to login the Admin user with a blankpassword. If the log in is successful, MS Access continuesloading and the user never realizes that they were loggedin as Admin. However, if the login is unsuccessful, say forexample the Admin user does not have a blank password,then a login dialog box pops up asking the user to specifya username and passwordWhen you create a new User, you will be prompted for aUser Name, Password, and a PID or PersonalIdentification number. A PID can be any text or numbersup to 20 characters long. All three values uniquely identifyeach user.101

The database.MDB fileMS Access verifies that the user name and password existin the Workgroup Information File. After the user has beenverified, the workgroup information file’s job is done. TheMDB itself stores security rights and privileges for eachuser and for each database object.The MDB will have a list of user id’s and the privileges thateach user may have. One user may have the rights to openthe table, but not delete any records, or change the designof the table. Another user may not have any restrictions atall. The MDB file knows each user’s privileges. Thedistinction between the workgroup information file

Databases for beginners 02-DBBA Marek Kręglewski. About the course Steven Roman, Access Database Design & . Home library – table Books . SQL – Structured Query Language Types of queries: –Select q