Presentation is loading. Please wait.

Presentation is loading. Please wait.

Databases part 2 – field properties

Similar presentations


Presentation on theme: "Databases part 2 – field properties"— Presentation transcript:

1 Databases part 2 – field properties
Chapter 9 Asfia Rahman

2 Steps to create relationship
Identify entities Determine fields Determine field sizes Establish relationships Make ERD Implement the tables in Access Apply validations Make relationships Paper work Asfia Rahman

3 Data types Data type Use Text
Use for alphanumeric characters, including text, or text and numbers, that are not used in calculations (for example, a product ID). Memo Use for text greater than 255 characters in length, or for text that uses rich text formatting. Examples include notes, lengthy descriptions, and paragraphs that use text formatting, such as bold or italics. Use the Text Number Use for storing numeric values (integers or fractional) that will be used in calculations, except for monetary values. NOTE: Use the Currency data type for monetary values. Date/Time Use for storing date and time values. Note that each stored value includes both a date component and a time component. Currency Use for storing monetary values (currency). AutoNumber Use for generating unique values that can be used as a primary key, which Access inserts when a record is added. Note that AutoNumber fields can be incremented sequentially or by a specified increment, or assigned randomly. Yes/No Use for Boolean values: Yes/No, True/False, or On/Off. OLE Object Use for storing OLE objects from other Microsoft Windows programs. (Pictures) Attachment Use for storing binary files (that is, files that you cannot read by using a text editor), such as digital images (photos and graphics) or files created by using other Microsoft Office products. You can attach more than one file per record to an Attachment field. Hyperlink Use for storing hyperlinks, which provide single-click access to Web pages through a URL (Uniform Resource Locator) or to files through a name in UNC (universal naming convention) format. You can also link to Access objects that are stored in a database. Lookup Wizard Use to start the Lookup Wizard so that you can create a field that uses a combo box to look up a value in another table, query, or list of values. Note that Lookup Wizard is not an actual data type. Asfia Rahman

4 Field properties in access
Field size Format Input mask Caption Default value Validation rule Validation text Required Allow zero length Indexed field properties in the Customer table Asfia Rahman

5 1. Field size Text (Short text/long text) Number
Maximum number you can enter in the field. Max number is 255. Number The size and type of number Byte, integer, long integer, Single, Double, Decimal Most common are long integer and double Asfia Rahman

6 2. Format Display layout for the field.
You can select a pre-defined or custom format For pre- defined NUMBERS General number -  Displays the number as it was entered. Currency - Displays the number by using the thousand separator, and applies the windows settings for currency ($ or pounds) is displayed as $3, Euro - Displays the number using the Euro currency symbol, regardless of the symbol specified in the Regional and Language Options.   is displayed as €3,456.79, Fixed – Displays at least one digit and applies the settings in the Regional and Language Options in Control Panel. For example, is displayed as Standard - Displays the number by using the thousand separator and applies the settings in the windows. This format does not display a currency symbol. Percentage - Multiplies the value by 100 and displays the number with a percent sign appended to the end is displayed as 35%. Scientific - Displays the value in standard scientific notation is displayed as 3.46E+03. Asfia Rahman

7 2.1 Custom Formats in Access
The data in your database comes with predefined formats but when you want something different, you can use custom formats. Since custom formatting only changes how the data is displayed, you don’t have to worry about any changes to the data To create a custom format, you’ll enter various characters in the Format property of a table field. The characters can be placeholders (such as 0 and #), separators (such as periods and commas), literal characters, and colors based on how you want the formatting to be. Custom number formats can have one to four sections with semicolons (;) as the list separator. Each section contains the format specification for a different type of number. Section Description First The format for positive numbers. Second The format for negative numbers. Third The format for zero values. Fourth The format for Null values. $#,##0.00[Green];($#,##0.00)[Red];"Zero";"Null" Asfia Rahman

8 Example of custom formatting:
#,###.##;(#,###.##)[Red];0,000.00;"Undefined" Here’s what the formatting means The number sign (#) is a Placeholder for digits. If there are no values, Access displays a blank space. To display zeroes instead of blank spaces.  For example: to display 1234 as , use the number 0 as the placeholder like this ####.00. Positive values with two decimal places. Negative values with two decimal places, in parentheses and red type. Zero values as the number 0, always with two decimal places. Null values as the word "Undefined." Asfia Rahman

9 If you choose to create a format for each type of value, you must put the format for positive values first, the format for negative values second, the format for zero values third, and the format for null values last. Also, you must separate each format with a semicolon. If you use multiple sections but don't specify a format for each section, entries for which there is no format will either display nothing or default to the formatting of the first section. Asfia Rahman

10 Digit placeholder. Display a digit or 0.
Symbol Description . (period) Decimal separator. Separators are set in the regional settings in Windows. , (comma) Thousand separator. Digit placeholder. Display a digit or 0. # Digit placeholder. Display a digit or nothing. $ Display the literal character "$". % Percentage. The value is multiplied by 100 and a percent sign is appended. Asfia Rahman

11 0;(0);;"Null" Display positive values normally; display negative values in parentheses; display the word "Null" if the value is Null. +0.0;–0.0;0.0 Display a plus (+) or minus (–) sign with positive or negative numbers; display 0.0 if the value is zero. Asfia Rahman

12 Zero-length string ("") 5 -5 0.5 1 0.00 5.00 -5.00 0.50 #,##0
Format (Style) "5" formatted as "-5" formatted as "0.5" formatted as "0" formatted as Zero-length string ("") 5 -5 0.5 1 0.00 5.00 -5.00 0.50 #,##0 $#,##0;($#,##0) $5 ($5) $1 $0 $#,##0.00;($#,##0.00) $5.00 ($5.00) $0.50 $0.00 0% 500% -500% 50% 0.00% 500.00% % 50.00% 0.00E+00 5.00E+00 -5.00E+00 5.00E-01 0.00E-00 5.00E00 -5.00E00 0.00E00 "$#,##0;;\Z\e\r\o" $-5 Zero Asfia Rahman

13 Boolean format For Yes/No
True/False — Displays the value as either True or False. Yes/No — Displays the value as either Yes or No. On/Off — Displays the value as either On or Off. NOTES:  True=Yes=On = -1 and False=No=Off = 0 Asfia Rahman

14 3. Input masks To restrict data entry ? – may enter letter (optional),
Helps with validation A – must enter letter or digit (obligatory), Checks data while its being typed a – may enter letter or digit (optional), mask can be designed with a mask creator (text or data/time fields) or manually & – any character or space (obligatory), C – any character or space (optional), according to the pattern. . , : ; - / – separators, The most common symbols are: < – all letters will be converted to lower case, 0 – digit (obligatory), > – all letters will be converted to upper case, 9 – digit or space character (optional), n – any following character will be displayed as a regular one; # – digit, space, + or - (optional, in edition mode spaces are displayed as empty places but they are removed when saving data), Setting the input mask property to “Password” creates a format for entering passwords. Any character will be displayed as an asterisk “*”. L – must enter letter (obligatory), Asfia Rahman

15 Input masks example (000) 000-0000 (206) 555-0199
This input mask Provides this type of value Notes (000) (206) In this case, you must enter an area code because that section of the mask (000, enclosed in parentheses) uses the 0 placeholder. (999) ! (206) ( ) In this case, the area code section uses the 9 placeholder, so area codes are optional. Also, the exclamation point (!) causes the mask to fill in from left to right. (000) AAA-AAAA (206) 555-TELE Allows you to substitute the last four digits of a U.S. style phone number with letters. Note the use of the 0 placeholder in the area code section, which makes the area code mandatory. #999 Any positive or negative number, no more than four characters, and with no thousands separator or decimal places. >L????L?000L0 GREENGR339M3  MAY R 452B7 A combination of mandatory (L) and optional (?) letters and mandatory numbers (0). The greater-than sign forces users to enter all letters in uppercase. To use an input mask of this type, you must set the data type for the table field to Text or Memo. A mandatory postal code and an optional plus-four section. >L<?????????????? Maria Pierre A first or last name with the first letter automatically capitalized. ISBN 0-&&&&&&&&&-0 ISBN A book number with the literal text, mandatory first and last digits, and any combination of letters and characters between those digits. >LL DB A combination of mandatory letters and characters, all uppercase. Use this type of input mask, for example, to help users enter part numbers or other forms of inventory correctly. Asfia Rahman

16 4. caption Label to display if the control is used in a FORM
Helps in designing of the forms when automatically generating FORMS Asfia Rahman

17 5. Default value Any value that will be saved no matter the user inputs the data or not. Helps in maintain data integrity and consistency. Helps in applying presence checks Asfia Rahman

18 6. Validation rules Restrict data entry Checks data after its entered.
There are a variety of validation rules that can be used within a database including: lookup in list (by looking up in a list entered within the rule) lookup in list (by using referential integrity) lookup in list (by using a lookup table) range data type format length presence. Asfia Rahman

19 Text validations Wildcard characters:
The asterisk (*) represents zero or more characters. ? to match a single character # character plays a similar role, but it represents a number Asfia Rahman

20 Like "[A-Z][A-Z][A-Z][A-Z][A-Z][A-Z][A-Z]"
Square brackets can restrict any character to certain letters or symbols. Suppose your company uses an eight-character product code that always begins with A or E. Here’s the validation rule you need: Like "[AE]???????" Note that the [AE] part represents one character, which can be either A or E. If you wanted to allow A, B, C, D, you’d write [ABCD] instead, or you’d use the handy shortcut [A-D], which means “allow any character from A to D, including A and D.” An expression which allows a seven-letter word and doesn’t allow numbers or symbols. It works by repeating the [A-Z] code (which allows any letter) seven times. Like "[A-Z][A-Z][A-Z][A-Z][A-Z][A-Z][A-Z]" Asfia Rahman

21 Text validation examples
Like "R*" Like "*ed" Like "*a*b*" Like Like "?????0ZB" Like "#####0ZB" Like "a?b?c“ Like ?* Asfia Rahman

22 example Type Field Rule Lookup in list Gender "M" or "F" Title
IN ("M r", "Mrs", "Miss", " Dr") Range Date of Birth >DATE() (must be after today 's date) Date Joined > 28/02/1995 Reorder Amount Between 1 and 2000 Reorder Level  >0 Data Type State  (must be two text characters) Like “[A-Z][A-Z]” Format   Address Like (* means an character)  Length  Colour  Like 'c??" (must be two characters) Presence  Forename  IS NOT NULL Asfia Rahman

23 Operator Function Example NOT
Tests for converse values. Use before any comparison operator except IS NOT NULL. NOT > 10 (the same as <=10). IN Tests for values equal to existing members in a list. Comparison value must be a comma-separated list enclosed in parentheses. IN ("Tokyo","Paris","Moscow") BETWEEN Tests for a range of values. You must use two comparison values — low and high — and you must separate those values with the AND separator. BETWEEN 100 AND 1000 (the same as >=100 AND <=1000) LIKE Matches pattern strings in Text and Memo fields. LIKE "Geo*" IS NOT NULL Forces users to enter values in the field. This is the same as setting the Required field property to Yes. However, when you enable the Required property and a user fails to enter a value, Access displays a somewhat unfriendly error message. Typically, your database is easier to use if you use IS NOT NULL and enter a friendly message in the Validation Text property. AND Specifies that all parts of the validation rule must be true. >= #01/01/2007# AND <=#03/06/2008# NOTE:  You can also use AND to combine validation rules. For example: NOT "UK" AND LIKE "U*". OR Specifies that some but not all parts of the validation rule must be true. January OR February < Less than. <= Less than or equal to. > Greater than. >= Greater than or equal to. = Equal to. <> Not equal to. Asfia Rahman

24 Value must be zero or greater. -or- You must enter a positive number.
Validation rule Validation text <>0 Enter a nonzero value. >=0 Value must be zero or greater. -or- You must enter a positive number. 0 or >100 Value must be either 0 or greater than 100. BETWEEN 0 AND 1 Enter a value with a percent sign. (For use with a field that stores number values as percentages). <#01/01/2007# Enter a date before 2007. >=#01/01/2007# AND <#01/01/2008# Date must occur in 2007. <Date() Birth date cannot be in the future. >=Int(Now()) Enter today's date. M Or F Enter M for male or F for female. LIKE OR OR Enter a valid .com, .net, or .org address. [RequiredDate]<=[OrderDate]+30 Enter a required date that occurs no more than 30 days after the order date. [EndDate]>=[StartDate] Enter an ending date on or after the start date. Asfia Rahman

25 using input masks for email addresses
Because addresses vary widely in the number of characters they contain, input masks are not a good tool for ensuring that addresses are entered correctly. Instead, we recommend using the Validation Rule and Validation Text properties. The validation rule shown in the following table ensures that the address is entered with one or more characters, then an sign, then one or more characters, then a period, and then one or more characters. For be allowed, not. If you enter an address that doesn’t match the validation rule, Access doesn’t accept the input and displays the message in the Validation Text property. If no text is entered in the Validation Text property box, Access displays a generic message. Validation Rule Is Null Or ((Like And (Not Like "*[ ,;]*")) Validation Text(optional) Please enter the address with an sign and the full domain name (for example, Asfia Rahman

26 required Require data in this field?
If selected YES, user must enter data, cannot leave blank Helps in implementing presence check Asfia Rahman

27 Allow zero length Can user enter 0 length strings?
Applies to TEXT data types Asfia Rahman

28 indexed Selecting “Yes, No duplicates” prohibits any repetition of data. Helps when creating one-to-one relationships Asfia Rahman

29 Task Open the database 9_01 Review all tables List the entities
Write the attributes Specify data types and field sizes used Make the ERD Note down any type of data restriction/validation used on the fields and explain what is being done. Asfia Rahman


Download ppt "Databases part 2 – field properties"

Similar presentations


Ads by Google