第八讲 定义表之间的关系前面定义了主键,以及相应的表后,就可以制定各表部的关系,从而建立起一个关系数据库。的应用与管理关系数据库,中文Access2000具有很强的能力,这正是中文Visual FoxPro 6与中文Excel 2000所不及的。为了建立关系数据库,首先要建立
注意:中文Access 2000不能在已打开的表之间创建或修改关系,所以要关闭所有打开的表,这与中文Visual FoxPro6有些不一样。步骤一、按下键盘上的F11功能键,将当前操作窗口切换到“数据库”窗口。
步骤二、单击“数据库”工具栏中的“关系”按钮,参见图39。
此后,如果当前数据库中已经存在着关系表,屏幕上就将显示如图40所示的“关系”对话框。如果当前数据库没有定义任何关系,中文Access 2000将会自动显示“显示表”对话框,让您从中选择加入要建立关系的表,如图41所示。
图39单击这个按钮
图40从此快捷菜单中选择该命令
如果需要添加的关系表没有在“关系”对话框中列出,那么就需要进入“显示表”对话框,为此可以右击“关系”对话框中任意处,然后从一份快捷菜单中选择“显示表”命令,参图41。接下来就可以在这个对话框的“表”选项卡中选择要加入的表,然后单击“添加”按钮。下面的操作将使用“雇员和任务”、“客户与销售量”、“客户与合同金额”这三张数据表,它们全都是在此之前建立的,所输入的数据记录也很简单,各字段如图42所示,您可以自己建立好。
图41进入“显示表”对话框
图42为这三张表建立关系
注:为几张表建立关系的目的就是要让它们组成关系数据库,也就是成为“相关表”。
步骤三、从某张表中将相关字段拖动到另一张表中的相关字段上。
若要拖动多个字段,可在拖动之前按下键盘上的Ctrl键并单击每一个要拖动的字段,这样即可选它们。在大多数的情况下,中文Access 2000要求将表中的主键字段(以粗体文本显示)拖动到其他表中的名为外部键的相似字段(经常具有相同的名称),如图42中就显示出各表中那个都有的ID字段。相关字段不需要有相同的名称,但它们必须有相同的数据类型(只有两种例外的情况),以及包含相同种类的内容。此外,当匹配的字段是“数字”字段时,它们必须有相同的“字段大小”属性设置。匹配数据类型的两种例外情况是:
图43进入“编辑关系”对话框
1.“自动数字”字段与“字段大小”属性设置为“长整型”数据类型的“数字”字段能匹配。
2.“自动数字”字段与“字段大小”属性设置为“同步复制 ID”数据类型的“数字”字段能匹配。
步骤四、在图43所示的“编辑关系”对话框中,检查显示在两个列中的字段名称是否相同。以确保正确性。必要时可以在此更改。若需要,还可以设置关系选项。最后单击“创建”按钮。
图44上述操作的结果
接下来,您可以参照这几步操作对每一张要建立关联的表进行操作。本章例所使用的主键是ID字段,所以操作的结果将如图44所示。在该插图中,各表中的ID字段使用了一条折线与另一张的相同字段相连接,这是Access2000关联关系的方法。此后,关闭“关系”窗口时,屏幕上还将显示提示询问是否要保存此布局配置。不论是否保存此配置,所创建的关系都已保存在当前数据库中。
注意:如果要查看数据库中定义的所有关系,可单击“数据库”工具栏中的“显示所有关系”按钮。如果只要查看某一张表中所定义的关系,则请单击此表,然后单击“数据库”工具栏中的“显示直接关系”按钮。若要更改表的设计,可右击它后通过快捷菜单中的“表设计”命令进行操作。
总结:
本部分所介绍的中文Access 2000,这个软件在数据处理方面的功能非常强大,突出的特点是它那可视化的操作方式。若您在已经清楚地掌握了数据库与表的建立和应用方法,以及相关概念,那么在这里学习起来就不会感到吃力,本教程中所提供的示例也没有使用较多的字段,数据记录也只有几行,您能很容易的建立好它们。接下来,本教程将应用所建立的索引与关系来应用中文Access 2000,您将会看到与中文Visual FoxPro6不同的操作方法,而它们的功能其实都差不多。
思考题:
1.在中文Access 2000可建立数据库与表的操作方法是什么?
2.本章中所用的“窗体”、“窗口”、“对话框”大致有哪些?各自的特点是什么?
3.什么是“主键”?为什么要用它?
4.创建索引与定义表之间的关系各自是如何操作的

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

MySQL is suitable for small and large enterprises. 1) Small businesses can use MySQL for basic data management, such as storing customer information. 2) Large enterprises can use MySQL to process massive data and complex business logic to optimize query performance and transaction processing.

InnoDB effectively prevents phantom reading through Next-KeyLocking mechanism. 1) Next-KeyLocking combines row lock and gap lock to lock records and their gaps to prevent new records from being inserted. 2) In practical applications, by optimizing query and adjusting isolation levels, lock competition can be reduced and concurrency performance can be improved.

MySQL is not a programming language, but its query language SQL has the characteristics of a programming language: 1. SQL supports conditional judgment, loops and variable operations; 2. Through stored procedures, triggers and functions, users can perform complex logical operations in the database.

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

MySQL is an open source relational database management system suitable for data storage, management, query and security. 1. It supports a variety of operating systems and is widely used in Web applications and other fields. 2. Through the client-server architecture and different storage engines, MySQL processes data efficiently. 3. Basic usage includes creating databases and tables, inserting, querying and updating data. 4. Advanced usage involves complex queries and stored procedures. 5. Common errors can be debugged through the EXPLAIN statement. 6. Performance optimization includes the rational use of indexes and optimized query statements.

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

InnoDB's lock mechanisms include shared locks, exclusive locks, intention locks, record locks, gap locks and next key locks. 1. Shared lock allows transactions to read data without preventing other transactions from reading. 2. Exclusive lock prevents other transactions from reading and modifying data. 3. Intention lock optimizes lock efficiency. 4. Record lock lock index record. 5. Gap lock locks index recording gap. 6. The next key lock is a combination of record lock and gap lock to ensure data consistency.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use