Implement a micro-database and a micro-Database

Source: Internet
Author: User

Implement a micro-database and a micro-Database

Write a simple database by yourself,PrincipleThere are the following points:

1. Data is saved as text

Write the data to be saved to a text file, which is a database.

For easy reading, data must be divided into records. The length of each record must be equal.

For example, if the length of each record is 800 bytes, the starting position of the 5th record is 3200 bytes.

In most cases, we do not know the position of a record, but only the value of the primary key. In this case, a comparison record can be created to read data. However, the efficiency is too low.In practical applications, databases often store data in the B-tree format..

 

Ii. About B-tree

To understand Tree B, you must first understand the binary search tree.

Binary Search Tree is a highly efficient data structure with three features:

(1) Each node has a maximum of two Subtrees.

(2) The left subtree is smaller than the value of the parent node, and the right subtree is greater than the value of the parent node.

(3) Find the target value in n nodes. Generally, only log (n) comparisons are required.

 

The binary search tree structure is not suitable for databases because its search efficiency is related to the number of layers. The more data that falls under the lower layer, the more times the comparison is required. In extreme cases, it takes n times for n pieces of data to be compared to find the target value. For a database, data is read from the hard disk every time it enters a layer. This is fatal because the hard disk read time is much longer than the data processing time, and the less the number of times the database reads the hard disk, the better.

 

Tree B is an improvement on the binary search tree. Its design philosophy is to integrate the relevant data as much as possible to read multiple data at a time, reducing the number of hard disk operations.

Features of Tree B:

(1) A node can accommodate multiple values.

(2) No new layers will be added unless the data is filled up. That is to say, the less the B-tree pursues, the better.

(3) The value of the child node has a strict size correspondence with the value in the parent node. Generally, if the parent node has a value, there will be a + 1 subnode. For example, if a parent node has two values (7 and 16), it must have three subnodes. The first subnode has a value smaller than 7, and the last subnode has a value greater than 16, the subnode in the middle is the value between 7 and 16.

 

This data structure helps to reduce the number of hard disk reads. Assuming that a node can contain 100 values, the layer-3 B tree can accommodate 1 million data records. If it is changed to a binary search tree, it requires 20 layers. Assuming that the operating system reads a node at a time and the root node is kept in the memory, the B-tree searches for the target value in the 1 million data records and only needs to read the hard disk twice.

 

Iii. Index

The database is stored in the B-tree format and only solves the problem of searching data based on the "primary key. If you want to search for other fields, you need to create an index ).

The so-called index is a B-tree file with a field as the keyword. Assume that an "Employee table" contains two fields: employee ID (primary key) and name. You can create an index file for the name, this file stores names in Tree B format. Each name is followed by its location in the database (that is, the number of records ). When searching for a name, first find the corresponding number of records from the index, and then read from the table. This index search method is called the index sequential access method, abbreviated as ISAM. It has multiple implementations. You only need to use these code libraries to write the simplest database.

 

Iv. Advanced functions

After the most basic data access (including indexes) is deployed, some advanced functions can be implemented.

(1)SQL languageIt is a common operating language for databases. Therefore, an SQL parser is required to parse SQL commands into corresponding ISAM operations.

(2)Join)The two tables in the database are connected through a foreign key. You need to optimize this operation.

(3)Database transactions(Transaction) refers to the batch operation of a series of database operations, as long as one step fails, the entire operation is not successful. Therefore, an "operation log" is required to roll back the operation in case of failure.

(4)Backup mechanism: Save the database copy.

(5)Remote Operation: Enables users to operate databases on different machines through TCP/IP protocol.

 

 

Some of the content comes from clicking the open link and will be updated and improved in the future.

 

 

 


If you want to build a small database, what do you suggest? What are the database options for SQL?

Database Design Methods, specifications and skills
I. Database Design Process
Database technology is the most effective means of information resource management. Database Design refers to constructing the optimal database mode for a given application environment, establishing a database and its application system, and effectively storing data to meet user information requirements and processing requirements.
In the demand analysis phase of database design, the application requirements of various users are integrated (real-world requirements ), in the conceptual design stage, a conceptual model (information world model) independent of the machine characteristics and various DBMS products is formed, which is described by E-R diagram. In the logic design stage, the E-R diagram is converted into the data model supported by the specific database product, such as the relational model, to form the database logic model. Then, based on the user's processing requirements and security considerations, the necessary VIEW is created on the basis of the basic table to form an external data mode. In the physical design phase, you can arrange physical storage based on the characteristics and processing needs of the DBMS, design indexes, and form the internal database mode.
1. Demand analysis stage
Requirement collection and analysis: the data requirement described by the data dictionary is obtained (and the processing requirement described by the data flow diagram ).
Requirement Analysis focuses on investigating, collecting, and analyzing users' information requirements, processing requirements, and security and integrity requirements in data management.
Requirement Analysis Methods: Investigate the organization and organization, investigate the business activities of each department, assist users in clarifying various requirements for the new system, and determine the boundaries of the new system.
Common survey methods include: follow-up operations, opening survey meetings, inviting special personnel to introduce, ask, and designing surveys. Users are requested to fill in and check records.
The methods for analyzing and expressing user requirements mainly include top-down and bottom-up methods. The top-down Structured Analysis method (SA) starts with the upper-level system organization and analyzes the system layer by layer, the data flow diagram and data dictionary are used to describe each layer.
The data flow chart shows the relationship between the data and the processing process. The Data in the system is described using the Data Dictionary (DD.
A data dictionary is a collection of various data descriptions. It describes the data in a database, that is, metadata, rather than the data itself. A data dictionary consists of data items, data structures, data streams, data storage, and processing processes (at least the Data Type of each field and the Primary and Foreign keys in each table should be included ).
Data item description = {data item name, description, alias, data type, length,
Value range, value meaning, and logical relationship with other data items}
Data Structure Description = {Data Structure name, description, composition: {data item or data structure }}
Data Stream description = {data stream name, description, data stream source, data stream destination,
Composition: {data structure}, average traffic, peak traffic}
Data storage description = {data storage name, description, number, inbound data stream, outbound data stream,
Composition: {data structure}, data volume, access method}
Process description = {process name, description, input: {data stream}, output: {data stream },
Handling: {brief description }}
2. Conceptual Structure Design Stage
A conceptual model independent of a specific DBMS is formed through the synthesis, induction and abstraction of user requirements, which can be expressed by a E-R diagram.
The conceptual model is used for modeling the information world. The conceptual model does not depend on the data model supported by a DBMS. A conceptual model can be converted to a specific data model supported by a DBMS on a computer.
Concept model features:
(1) Strong semantic expression ability, which can easily and directly express various semantic knowledge in applications.
(2) It should be simple, clear, and easy to understand. It is a language for communication between users and database designers.
A common method for conceptual model design is the IDEF1X method, which applies the entity-contact method to a Semantic Modeling Technology in the semantic data model and is used to establish a system information model.
The steps to create a E-R model using the IDEF1X method are as follows:
2.1 Step 1 -- initialize the project
In this phase, the task starts from the description of the purpose and scope, determines the modeling target, develops the modeling plan, and organizes the modeling... the remaining full text>

What tools are required to create a small database and create a simple interface for adding, deleting, querying, and modifying databases?

Asp + sqlserver on the line, simple programming, B/s structure as well as comfortable, no installation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.