BẢNG DỮ LIỆU (TABLES)
1
NỘI DUNG
1
KHÁI NIỆM
2
CÁCH TẠO BẢNG
3
CÁC KIỂU DỮ LIỆU
4
CÁC THUỘC TÍNH CỦA TRƯỜNG(CỘT)
2
2
KHÁI NIỆM
Là thành phần cơ bản trong CSDL của Access,
dùng để lưu trữ dữ liệu
Thành phần
Tên bảng
Cột/ trường (field): lưu trữ một thuộc tính của đối
tượng
Dòng/ mẩu tin (record): là một thể hiện dữ liệu của các
trường trong bảng
Khóa chính (primary key)
Khóa ngoại (foreign key)
3
VÍ DỤ
4
KHÓA CHÍNH (PRIMARY KEY)
Là tập hợp của một hay nhiều cột
Dùng để phân biệt giữa các dòng khác nhau trong cùng
một bảng
Khóa chính phải là duy nhất, không được trùng và không
phép rỗng.
5
KHÓA NGOẠI (FOREIGN KEY)
Là tập hợp của 1 hay nhiều cột, các cột này phải
là khóa chính của một bảng khác
Dùng để tạo quan hệ giữa các bảng trong CSDL
6
TẠO BẢNG BẰNG TABLE DESIGN(1/4)
7
TẠO BẢNG BẰNG TABLE DESIGN(2/4)
Field Properties
8
TẠO BẢNG BẰNG TABLE DESIGN(3/4)
Xác định khóa chính
Lựa chọn thuộc tính (hoặc các thuộc tính) được sử
dụng làm khóa chính
Chọn nút Primary Key trên Table tools
Hoặc R-click trên tên thuộc tính, chọn Primary Key
9
TẠO BẢNG BẰNG TABLE DESIGN(4/4)
Lưu bảng vừa tạo
Sử dụng nút Save trên Quick Access Toolbar, hoặc Save
trong tab File, hoặc Ctrl+S
Đặt tên cho bảng
Chú ý: Nếu bảng không có khóa chính
10
TẠO BẢNG TRONG CHẾ ĐỘDATASHEET
VIEW (1/2)
11
TẠO BẢNG TRONG CHẾ ĐỘDATASHEET
VIEW (2/2)
12
CÁC KIỂU DỮ LIỆU (DATA TYPES)(1/4)
1. Text
8. OLE Object
2. Memo
9. Attachment
3. Number
10. Hyperlink
4. Date/time
11. Lookup wizard
5. Currency
12. Calculated
6. AutoNumber
13. Rich text
7. Yes/No
13
DATA TYPES (2/4)
DATA TYPES
USE
SIZE
Text
Use for alphanumeric character
Up to 255 characters
Memo
Use for text greater than 255
characters in length
Up to 65,535 characters
Number
Use for storing numeric values
1, 2, 4, 8 or 12 bytes (16
bytes when used for
replication ID)
Date/Time
Use for storing date and time values
8 bytes
Currency
Use for storing monetary values
8 bytes
AutoNumber
Use for generating unique values
that can be used as a primary key
4 bytes (16 bytes when
used for replication ID)
14
DATA TYPES (3/4)
DATA TYPES
USE
SIZE
Yes/No
Use for Boolean values
1 bit
OLE Object
Use to hold a graphic or other
objects. Objects can be linked or
embedded
Up to 1 GB
Attachment
Use to attach a file to a record
(similar to file attachment in email)
2 GB for compressed
attachments, ~700KB for
uncompressed ones
Hyperlink
Use for storing hyperlink
Up to 65,535 characters
15
DATA TYPES (4/4)
DATA TYPES
USE
SIZE
Lookup Wizard *
Use to start the Lookup Wizard so
that we can create a field that uses
a combo box to look up a value in
another table, query, or list of
values
Note: Lookup Wizard is not an
actual data type
• If the lookup field is
bound to a table or a
query, the size of the
bound column is used
• Otherwise, the size of
text field is used
Calculated *
Use to hold the results of a
calculation based on other fields in
the same tables
Rich text
Use for text fields that require up
to 65,535 alphanumeric characters
with character formatting
16
FIELD PROPERTIES (1/6)
FIELD PROPERTIES
Field Size
Format
Decimal Places
ASSOCIATED DATA TYPES
Text
Number
AutoNumber
Text
Memo
Number
Date/Time
Currency
AutoNumber
Yes/No
Hyperlink
Number
Currency
USE
Set the maximum size for stored
data
Customize the way that the field
appears by default when it is
displayed or printed
Specify the number of decimal
places to use when displaying
numbers
17
FIELD PROPERTIES (2/6)
FIELD PROPERTIES
ASSOCIATED DATA TYPES USE
New Values
AutoNumber
Incremented or random value is used
Input Mask
Text
Number
Date/Time
Currency
Display editing characters to guide data
entry
Caption
All data types
Set default labels for forms, reports, and
queries
Text
Memo
Number
Date/Time
Default Value
Currency
Yes/No
Hyperlink
Automatically assign the specified value
to a field when a new record is added
18
FIELD PROPERTIES (3/6)
FIELD PROPERTIES
ASSOCIATED DATA TYPES USE
Validation Rule
Text
Memo
Number
Date/Time
Currency
Yes/No
Hyperlink
Supply an expression that must be true
to add or change the value in this field
Validation Text
Text
Memo
Number
Date/Time
Currency
Yes/No
Hyperlink
Enter text that appears when a value
entered this field violates the expression
in the Validation Rule box
19
FIELD PROPERTIES (4/6)
FIELD PROPERTIES
ASSOCIATED DATA TYPES USE
Required
All data types except
AutoNumber
Require that this field must contain a
value in every record
Allow Zero Length
Text
Memo
Hyperlink
Allow entry (by setting to Yes) of a zerolength string (“”)
Indexed
Text
Memo
Number
Date/Time
Currency
AutoNumber
Yes/No
Hyperlink
Speed up read access to data in this field
by creating and using an index
20
FIELD PROPERTIES (5/6)
FIELD PROPERTIES
ASSOCIATED DATA TYPES
USE
Unicode Compression
Text
Memo
Hyperlink
Compress the data in this field
when fewer than 4,096 characters
IME Mode
Text
Memo
Date/Time
Hyperlink
Control conversion of characters in
East-Asian versions of Windows
IME Sentence Mode
Text
Memo
Date/Time
Hyperlink
Control conversion of sentences in
East-Asian versions of Windows
21
FIELD PROPERTIES (6/6)
FIELD PROPERTIES
Smart Tags
Append Only
ASSOCIATED DATA TYPES
Text
Memo
Number
Date/Time
Currency
AutoNumber
Hyperlink
Memo
Hyperlink
USE
Attach a smart tag to the field
Track field value history
Text Format
Memo
Select Rich Text to store field data as
HTML, Plan Text to store only text
Text Align
All data types except
Attachment
Specify default alignment of text
Show Date Picker Date/Time
Display a date picker
22
FIELD PROPERTIES – FIELD SIZE
DATA TYPES
VALUE
Text
1 - 255
Number
AutoNumber
Expressed data
Byte
Integers from 0 to 255
Integer
Integers from -32,768 to 32,767
Long integer
Integers from -2,147,483,648 to 2,147,483,647
Single
Float from -3.4x1038 to 3.4x1038 and up to 7 significantdigits
Double
Float from -1.797x10308 to 1.797x10308 and up to 15
significant digits
Replication ID
Globally unique identifier for replication (16 bytes for
storage)
Decimal
From -1028-1 to 1028-1, and up to 20 significant digits
Long integer
ReplicationID
23
FIELD PROPERTIES – FORMAT
Custom text format
Ví dụ: @”.com”; “no link”[red]
24
FIELD PROPERTIES – FORMAT
Predefined Number format
25