The most important use of ASP is to build dynamic websites. Build Dynamics Website construction , you should always deal with the database. Therefore, convenient and fast access to the database has become an important function of ASP. In most examples in this book, database access is required. We will encounter a large number of database access operations. Therefore, in this chapter, we first learn the basics of accessing databases in ASP. Whether the database access control of ASP can be flexibly used to access the database will directly determine a series of performance such as the execution efficiency of ASP programs.
When browsing the web, we can often see websites that provide data query functions. For example, in some publishing houses' websites, as long as the title, author or certain keywords of the book are known, we can find relevant information about the book; or in some community websites, we can provide visitors with discussion areas, user registration and other services; There are also commodity queries on shopping websites The operation of these website functions usually needs the support of the background database. The website background service program will search for data in the background database of the website according to the information provided by the visitors, and will collate the search results or data back to the visitors. Therefore, such background database can be called the website database, that is, the Web data, Let's take a look at some basic concepts about Web databases.
SQL is the abbreviation of Structured Query Language. SQL Language Education is a tool for organizing, managing and retrieving data stored in relational databases: when users want to retrieve data in relational databases, they send a request to the database management system (DBMS) through SQL Language Education, and then DBMS processes the SQL request, Finally, the processing result is returned to the user. This process is called database query. SQL is a language. To be exact, SQL is a sub language of database. SQL statements can be embedded into another language blindness, so that it has the database access function. SQL is also a non strict structured language. Its syntax is close to English sentences, so it is easy to understand. Most SQL statements are straightforward and read as clear as natural language. In most ASP applications, we will come into contact with databases, and the standard language we use for database operations when writing ASP applications is SQL, so the importance of SQL syntax is self-evident. Next, let's take a look at some common SQL commands.
Querying the database is the core function of the L language, and the SEIECF statement used to express the SQL query is the most powerful and complex SQL statement. It can retrieve the required data from the database and return the query result set to the user. SQL is a complete data processing language, which is not only used for database query, but also for inserting, modifying and deleting data records in the database. Compared with the complexity of SELECT statement of SQL query, the SQL statement that changes database content is relatively simple. However, for a DBMS, the risk caused by data update greatly exceeds that of data query. The database management system must protect the consistency of the stored data during the change period to ensure that effective data is entered into the database. The database must maintain consistency. The DBMS must also coordinate parallel updates of multiple users, To ensure that users and their changes will not affect other users' database operations. In this statement, the column names are separated by commas in parentheses, followed by the VALUES phrase and each column of data separated by commas in parentheses. However, it should be noted that the order of data and column names must be the same, and if the string type is used, it should be separated by single quotation marks. Conceptually, the INSERT statement creates a data row consistent with the table structure, fills it with the data in the VALUES clause, and then adds the new row to the table. The rows in the table are not sorted, so there is no concept of marking the row to the head or tail of the table or between two rows. After the INSERT statement ends, the new record is part of the table.
The INSERT statement can also add multiple rows of data to the target table. In this form of INSERT statement, the data value of the new row is explicitly specified in the statement body, but is obtained from the result of a database query operation specified in the statement. The added value comes from the database's own row, which seems strange, but it is very useful in certain states.