At the beginning of this article, I would like to thank some friends to believe that I pointed out the mistakes in the previous article. I don't know if I remember to give a simple page access counter using Application in the eighth article? I have a friend to ask me, why don't you have any effect on the last count result when he change the value of the counter start variable Numvisits? At first I was also confused, let us recall this source program as follows:
<%
DIM Numvisits
Numvisits = 0
Application.lock
Application ("Numvisits") = Application ("Numvisits") 1
Application.unlock
%>
Welcome to this page, you are the "" NumVisits ")%> Bit Visitor! In this program, if you try to change the value of the value by changing the variable Numvisits, it is absolutely Not. Because the value of the variable is changed to change the value of Application, both are not related. So here is redundant and assigning values for variables. So how should we define an initial value for Application ("Numvisits")? Please see the following correction procedures:
<%
IF Application ("Numvisits") <999 THEN
Application ("Numvisits") = 999
END IF
Application.lock
Application ("Numvisits") = Application ("Numvisits") 1
Application.unlock
%>
Welcome to this page, you are the "Numvisits")%> A visitor!
The 999 here is the initial value of the counter you want to set, so the problem is solved. I am very grateful to this friend who surnamed Kang gave me this mistake. Although this is just a small vulnerability, we need this rigorous and meticulous style in the process of writing procedures in the common school. I hope that friends will be Once the error in the discovery is, I will make a letter, I can correct it in time, thank you.
SQL language can be divided into two major parts: data definition language and data manipulation language, followed by the above after learning the SELECT statement in the data manipulation language, today the author should continue to briefly introduce the rest of the SQL statement.
SQL is a complete data processing language, not only for database queries, but also for data modifications and updates in the database, compared to complexity of SQL queries, change the SQL statement of the database content is simple. However, for a DBMS, the risk caused by data updates has greatly exceeded data queries. The database management system must protect the consistency of the stored data within the change period, ensure that valid data enters the database, the database must be consistent, and DBMS must also coordinate multiple user parallel updates to ensure that users and their changes are not affected. Other users' homework.
SQL statements used to modify the contents of the database mainly include the following:
1, INSERT, join a new data line to a table
2, delete, remove the data line from a table
3, Update, change the data already existing in the database
First let's take a look at INSERT:
Standard syntax:
INSERT INTO TABLE_NAME
(Col1, Col2 ...) Values (Value1, Value2 ...)
The following example should add the book as a new salesman to the table Salesreps
INSERT INTO
Salesreps (Name, Num, Sales, Hire_Date, INCOME)
Values ('Shusheng', 9, 10000, '23-Feb-99, 2000)
In this statement, the name of the column is listed in parentheses, and the next is Value phrase and parentheses, the data and column names should be noted. The order of the data and column names is the same, and If the string type is separated by single quotes. From the concept, the INSERT statement is established with a data line consistent with the table column structure, with the data from the VALUES clause to fill it, then add the new line to the table, the line in the table is not sorted. Therefore, there is no such concept between the head or the head or the end of the table. After the INSERT statement, the new line is part of the table.
The INSERT statement can also add multi-line data to the target table. In this form of Insert statement, the data value of the new row is not specified in the body of the statement, but a database query specified in the statement. The added value comes from the database itself, which seems to be a bit strange, but in some specific states, it is very useful. For example, you want to copy the order number, date, and number from December 30, 1998 from the Order table to another table named Oldorder, multi-line INSERT statement provides a compact and efficient to copy data. The method is as follows:
INSERT INTO Oldorder (Num, Date, Amount)
SELECT NUM, DATE, AMOUNT
From Order
WHERE DATE <'30 -12-98 '
This statement looks a bit complicated. It is actually very simple, the statement identifies the list of the list of the new row's table Oldorder and receives the data, which is completely similar to the single line INSERT statement. The remainder of the statement is a query that retrieves the data in the ORDER table. SQL performs queries for the Order table first, then insert the query result is to the Oldorder table.
Let's take a look at the UPDATE usage, the UPDATE statement is used to update a column or multiple columns of the selected line in the single table. To update the target table defined in the statement, the SET clause specifies which columns to update and calculate their values. The UPDATE statement always contains the WHERE statement, and the UPDATE statement is dangerous, so you must clearly recognize the importance of the WHERE statement, and where statements are used to specify rows that need to be updated.
Standard syntax:
Update Table_name
Set columnname1 = value1
[, columname2 = value2] ...
Where search_condition
The following is an example of a simple UPDATE statement:
Update Customers
SET CREDIT = 100000.00, ID = 99
Where name = 'ASP'
In this example, we update the credit value of customers named ASP in Table Customers to 100,000 and change his ID to 99. Look again below:
Update Customers
SET CREDIT = 200000.00, State = 021
WHERE ID in (80, 90, 100, 12)
We can find that in fact, the process of SQL handling the UPDATE statement is the list of specified by line, updating its search criteria, skipping its search criterion, is "false" or "empty" row. Finally, let's take a look at the DELETE statement.
Standard syntax:
Delete from TableName
WHERE CONDITION
Since it is too simple, the consequences caused are also serious, although it is optional, but it almost always exists, if the WHERE clause is omitted from the Delete statement, all of the target table The line will be deleted. Look at the example:
Delete from Order where id = 99
At the end of the article, the author is briefly introducing you to the data definition language. It is a statement used to create and modify the database structure, including CREATE and DROP statements.
1, CREATE statement
Standard syntax:
Create Table Table_Name
(Field1 Datatype [not null],
Field2 DataType [not null],
Field3 DataType [not null] ...)
Such as:
CREATE TABLE BILLS
(Name Char (30),
Amount Number,
Account_id number
Although Create Table is difficult to understand than the statement described in the previous, it is still very intuitive. It gives Bills to a new table and specifies the names and data types of the three columns in the table. After the table is established, we can add data. Such as:
INSERT INTO BILLS (Name, Amout, Account_ID) Values ('Gates', 100, 1)
If you don't need to save product information, you can use the DROP TABLE statement to remove the table and all the data it contain from the database from the database.
Standard syntax:
DROP TABLE TABLE_NAME
At this point, we have learned all common SQL statements, don't underestimate these simple statements that look like English, their features are very powerful, and they must be operated using them when we write ASP programs. From the next article, the author will introduce you to the built-in ActiveX component of the ASP, so stay tuned.