Data to create an interactive site, you need to use a database to store information from visitors. For example, if you want to build a site for a career introduction service, you need to store information such as a resume, a job that interests you, and so on. Creating dynamic leaf blades also requires a database, and if you want to show the best work that meets the needs of your visitors, you need to get the job information out of the database. You will find that in many cases the database needs to be used.
In this chapter, you will learn how to use Structured Query Language (SQL)) to manipulate databases. The SQL language is the standard language for the database. In active severpages, you need to use the SQL language whenever you want to access a database. Therefore, it is very important to have a good command of SQL for ASP programming.
Attention:
You can read "SQL" as a "sequel", or you can read it as a s-q-l by the pronunciation of a single letter. Both sounds are correct, with a large number of supporters in each of the pronunciations.
In this book, Think of "SQL" read as "sequel".
Through this chapter, you will understand how to implement database queries using SQL, you will learn how to use this query to retrieve information from the datasheet, and finally, you will learn how to set
Count and build your own database.
Attention:
With the introduction to SQL in the following chapters, you will have enough knowledge of SQL to effectively use active Sever Pages. However, SQL is a complex language,
The book cannot include all the details of it. To fully master the SQL language, you need to learn to use SQL in Microsoft SQL Sever. You can go to the bookstore nearby to buy
A Microsoft SQL Sever 6.5.
SQL Introduction:
This book assumes that you are a database that operates Microsoft SQL Sever in SQL. You can also use SQL to manipulate many other types of databases. SQL is the standard language for manipulating databases
Statement (In fact, there is a specific ANSI standard on the SQL language)
Attention:
Do not attempt to use Microsoft Access in place of Microsoft SQL Sever on your site. SQL Sever can serve many users at the same time, if you want your
The site has a high rate of access, and MS access is not competent.
Before you learn the specifics of SQL, you need to understand its two main features. One feature is easy to master, the other is a bit difficult to master.
The first feature is that all the data in the SQL database is stored in the table. A table is made up of rows and columns. For example, the following simple table includes name and e-mail
Address
This table has two columns (also called fields, domain):name, and email address.) There are three rows, and each row contains a set of data. The data in a row is grouped together, called a
Recording.
Whenever you add new data to a table, you add a new record. A data table can have dozens of records, or thousands of or billions of records. Although you
You may never need to store 1 billion email addresses, but it's always good to know you can do this, and maybe someday you'll have to.
Your database is likely to contain dozens of of tables, and all the information stored in your database is stored in these tables. When you consider how to store information in a database,
You should consider how to store them in a table.
The second feature of SQL is somewhat difficult to grasp. This language is designed to not allow you to retrieve records in a particular order, because doing so lowers the SQL sever fetch record
of efficiency. With SQL, you can only read records by query criteria.
When you think about how to take records out of a table, you naturally think of reading them by record location. For example, you might try to scan a record by a loop, to select
A specific record. When using SQL, you have to train yourself not to have this idea.
If you want to select all the names of "Bill Gates", if you use a traditional programming language, you might construct a loop that looks at the records in the table,
Whether the name field is "Bill Gates".
This method of selecting records is feasible, but not efficient. With SQL, you just say, "Select all name fields equal to the records of Bill Gates," and SQL will choose for you
All records that meet the criteria. SQL determines the best way to implement a query.
Build you want to take out the top 10 records in the table. Using the traditional programming language, you can do a loop, take out the first 10 records and end the loop. But using standard SQL queries,
It is impossible to achieve. From a SQL perspective, the concept of the first 10 records does not exist in a table.
At first, you will be frustrated when you know you can't use SQL to implement something that you feel should be able to achieve. You might be banging your head against the wall and even trying to write nasty letters to SQL.
Designers. But then you will realize that this feature of SQL is not just a limitation, but rather a strength. Because SQL does not read records based on location, it reads records to
Soon.
To sum up, SQL has two features: all data is stored in tables, and in the case of SQL, there is no order of records in the table. In the next section, you will learn how to use SQL from a table
Select a special record in the.
Use SQL to fetch records from a table.
One of the main functions of SQL is to implement database queries. If you are familiar with the Internet engine, then you are already familiar with the query. You use queries to obtain a letter that satisfies a specific condition
Interest. For example, if you want to find all the sites with ASP information, you can connect to Yahoo! and perform a search for active Sever pages. Before you enter this
After the query, you will receive a list of all the sites whose descriptions contain search expressions.
Most Internet engines allow logical queries. In a logical query, you can include special operators such as and, or, and not, and you use these operators to select specific notes
Recorded. For example, you can use and to limit query results. If you perform a search on active Sever Pages and SQL. You will get a description that contains both
Active Sever Pages and SQL Records. When you need to limit the results of a query, you can use and.
If you need to extend the results of the query, you can use the logical operator or. For example, if you perform a search, the search for all of its descriptions contains active Sever
Pages or SQL sites, the list you receive will include all sites whose descriptions contain two expressions or either of them.
If you want to exclude specific sites from the search results, you can use not. For example, querying "Active Sever Pages" and not "SQL" will return a column
Table, the site in the list contains active Sever Pages, but does not contain SQL. When a particular record must be excluded, you can use not.
Queries executed in SQL are very similar to searches performed on Internet search engines. When you execute an SQL query, by using a query condition that includes a logical operator,
You can get a list of records. The query results from one or more tables at this time.
The syntax for SQL queries is very simple. Suppose there is a table named Email_table, containing two fields of name and address, to get Bill Gates's E_Mail address, you
You can use the following query:
SELECT email from email_table WHERE name= "Bill Gates"
When this query executes, read Bill Gates's e_mail address from the table named Email_table. This simple statement consists of three parts:
The first part of the SELECT statement is named the column you want to select. In this case, only the email column is selected. When executed, only the value of the email column is displayed
Billg@microsoft.com.
The second part of the SELECTT statement indicates which table you want to query data from. In this case, the table name to query is email_table.
Finally, the WHERE clause of the SELECT statement indicates the record to choose what conditions to meet. In this case, the query condition is that only the value of the Name column is the record of Bill Gates
is selected.
Bill Gates is likely to have more than one email address. If the table contains multiple email addresses of Bill Gates. Use the above SELECT statement to read all of his
Email address. The SELECT statement removes from the table the value of the email field of all the Name field values for Bill Gates's records.
As I said earlier, queries can include logical operators in query criteria. If you want to read all the email addresses of Bill Gates or President Clinton, you can use the following
The query statement:
SELECT email from email_table WHERE name= "Bill Gates" OR
Name= "President Clinton"
The query condition in this example is a bit more complicated than the previous one. This statement selects all name listed in the table email_table as a record of Bill Gates or President Clinton. If the table contains multiple addresses of Bill Gates or President Clinton, all addresses are read.
The structure of the SELECT statement looks intuitive. If you ask a friend to choose a set of records for you from a table, you may present your request in a very similar way. In the SQL SELECT statement, you "Select a specific column from a table where some columns meet a specific condition".
The next section describes how to execute a SQL query to pick records. This will help you familiarize yourself with the different methods of fetching data from a table using a SELECT statement.
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