Ultradev instance tutorial: 2.1 Establishing a simple access database
Author:Eve Cole
Update Time:2009-05-30 18:35:12
Chapter 2: Setting up the database
Section 1: Create a simple access database
In this section we will learn about database creation. Friends who have used Access to create databases can skip it.
Open Microsoft Access, select File->New Database, and then choose a location to save your database file. Here we save it under its default name of db1.mdb.
After saving the database, we see the following interface. Double-click to create a table using the designer to start creating a data table. For the application we have here, you only need to follow the steps step by step. Even if you have never touched a database before, there is no problem. If you want to do in-depth applications involving relational structures, it is best to find a database. Let’s take a look at the book.
Next we design a user information table for user registration. Double-click to create a table using the designer to open the design interface. Fill in the user information you want to record in the field name column (it is best not to name the field name in Chinese, so that there will not be too much trouble when programming in the future, and also be careful not to use the database's own reserved words - --For example, temp. In this case, it will conflict with the database program. Try to name it with the table name + underscore + name, such as tbl_userinfo_name. Here we use simple naming first). We created a total of 6 fields, namely username (save the id for user registration), userpass (password for user registration), usermail (user's email address), reg_date (user registration time), homepage (user's personal homepage) address), phone (user’s contact number). The data type uses its default text type, and the field size is 50. Let’s deal with individual fields first.
Generally speaking, usernames, passwords, email addresses, and contact phone numbers will not exceed 50 characters (of course, if someone maliciously enters a string that is too long, an error will be reported, so we will do something in the subsequent web page production. limit), and the personal homepage address may exceed --- such as http://www.netease.com/~cosix/html/..., so we adjust its field size to 200.
The time type of the registration date is changed to date/time, *_' of course. Then we can call access's own function to add a default value for it, =Now(). This means that when data is added, the database system automatically uses the current time of the server as the value of the reg_date field, so that we can save the need to add it in the web page. Making entering the registration date is one step away.
After the modification is completed, click Save Chart on the toolbar to save our newly created table. A warning dialog box will pop up telling you that the table has not yet defined a primary key. Without a primary key, we cannot determine the unique status of this record in the table, and we will make mistakes when deleting or editing records, so we need to create a primary key. The value of the primary key will not be repeated. Click Yes to create the primary key.
As shown in the figure, a primary key named ID (with a key icon next to it) is created, and the data type is automatic numbering.
After clicking Save, this time you are asked to enter the name of the saved table. We named it after userinfo.
A table is created! Isn't it very simple?
Because we haven't learned how to create content for adding records, we will manually add some content here to facilitate our testing later. As shown in the picture.
Okay, a complete database has been established. What to do next? Well, let’s listen to the breakdown next time.