1. Trang chủ
  2. » Công Nghệ Thông Tin

Adobe Dreamweaver CS3 Unleashed- P22 ppt

50 207 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 50
Dung lượng 351,56 KB

Nội dung

Summary This chapter has introduced you to some simple, yet important, concepts—mainly data storage. You learned about the skeleton of a database—which is composed of tables, columns, and rows—and about crucial concepts that can aid in performance, maintenance, and efficiency. More importantly, you looked at the various databases supported in this book. You learned about Access, SQL Server 2005 Express Edition, and MySQL as well as the DBMSs that work in conjunction with them. You saw how to obtain and install the necessary software, how to create tables, columns, and rows, and how to attach/restore the Vecta Corp database so that you can work with dynamic Vecta Corp data in your database of choice from Dreamweaver. As the chapter progressed, we also looked at the many tables contained within the Vecta Corp database. You looked at the Employees, Departments, CreditCards, EmployeeStore, and Orders tables as well as the other tables left open so that you can continue to work with the Vecta Corp web application on your own. The next chapter, "A SQL Primer," goes beyond data storage and introduces you to the language used in data access—SQL. Chapter 23. A SQL Primer IN THIS CHAPTER The Structured Query Language Basic SQL Expressions Operators Functions Joins Subqueries Generating Queries Visually At this point, you are familiar with just how easy it is to create a database using Access, SQL Server 2005 Express, or MySQL. In the coming chapters, you'll learn just how easy Dreamweaver makes it to extract from, insert into, update within, and delete information from your database. Although Dreamweaver provides a simple process for the extraction of data from your database, you may quickly find your application growing far beyond the scope of simple data extraction. The kind of applications you eventually build will have a direct impact on how complex your use of a data-access language will be. Dreamweaver provides a simple and easy-to-use process for commonly used data extraction and filtering tasks, but if you truly want to get the most out of your application, you should become familiar with the topics discussed in this chapter. The Structured Query Language This chapter focuses on the language of today's database. The Structured Query Language, or SQL (pronounced "sequel"), was established in the 1970s as a way of interacting with current database technologies and the tables that made them up. With dozens of clauses, keywords, and operators, SQL quickly became the language standard for simple and complex database operations. The keywords that you construct, also known as statements, range from a simple few to a complex string of subqueries and joins. Although this chapter cannot begin to cover all there is to know on the subject, it can provide you with an introduction to beginning and advanced SQL statements, clauses, joins, subqueries, and action queries. The concepts you learn in this chapter will help you, on a more advanced level, interact with data in your database using Dreamweaver. Chapter 23. A SQL Primer IN THIS CHAPTER The Structured Query Language Basic SQL Expressions Operators Functions Joins Subqueries Generating Queries Visually At this point, you are familiar with just how easy it is to create a database using Access, SQL Server 2005 Express, or MySQL. In the coming chapters, you'll learn just how easy Dreamweaver makes it to extract from, insert into, update within, and delete information from your database. Although Dreamweaver provides a simple process for the extraction of data from your database, you may quickly find your application growing far beyond the scope of simple data extraction. The kind of applications you eventually build will have a direct impact on how complex your use of a data-access language will be. Dreamweaver provides a simple and easy-to-use process for commonly used data extraction and filtering tasks, but if you truly want to get the most out of your application, you should become familiar with the topics discussed in this chapter. The Structured Query Language This chapter focuses on the language of today's database. The Structured Query Language, or SQL (pronounced "sequel"), was established in the 1970s as a way of interacting with current database technologies and the tables that made them up. With dozens of clauses, keywords, and operators, SQL quickly became the language standard for simple and complex database operations. The keywords that you construct, also known as statements, range from a simple few to a complex string of subqueries and joins. Although this chapter cannot begin to cover all there is to know on the subject, it can provide you with an introduction to beginning and advanced SQL statements, clauses, joins, subqueries, and action queries. The concepts you learn in this chapter will help you, on a more advanced level, interact with data in your database using Dreamweaver. Basic SQL Just as your savings account would be useless without a valid ID or bank card to get to that money, information contained within a database is useless data unless you have the means of extracting it. SQL is the language that does just that; it allows for quick and complex access to the data contained in your database through the use of queries. Queries pose the questions and return the results to your application, usually in the form of a recordset. Caution Don't think of SQL as simply a way of extracting information. The SQL language can be complex, allowing not only queries from a database, but can add, modify, and delete information from a database as well. Consider trying to extract information from the EmployeeStore table of the Vecta Corp database. Recall that the EmployeeStore table resembles the table that follows (although this table does not show the ItemDescription and Headshot columns): Field Name Date Type ItemID AutoNumber ItemName Text Quantity Currency Cost Number You can then list products in rows that would look like the following: ItemID ItemName Cost Quantity 1 Vecta Corp Shirt $12.99 100 2 Vecta Corp Hooded $29.99 100 3 Vecta Corp Longsleeve $19.99 100 4 Vecta Corp Polo $23.99 100 5 Vecta Corp Sticker $1.99 100 6 Vecta Corp Mousepad $4.99 100 7 Vecta Corp Coffee Mug $6.99 100 8 Vecta Corp Water Bottle $9.99 100 Consider some important aspects about the previous table and the columns and data contained in the eight rows. The EmployeeStore table contains four columns: an ItemID with an AutoNumber that increments a value whenever an item is added, an ItemName that contains a Text data type allowing for a simple title of the product to be added, a column for Cost with a Currency data type that allows us to store price information for each specific item, and a Quantity column with a Number data type that allows us to store a numeric value indicating how many of a specific item we have left in our inventory. The last thing to consider is the data contained in the table. We are storing a list of Vecta Corp employee store items that are to be sold from the Web Store application. Now what? You have the table created, columns and data types have been outlined, and you have rows of data in the table. Our next step is to get to our data somehow. The next few sections outline how to use SQL to extract data from your tables. The SELECT Statement The foundation to all SQL queries is the SELECT statement. Made up of two keywords, the SELECT statement provides a means for retrieving the data from the database. In its simplest form, the SELECT statement is written using the following elements: SELECT—The SELECT keyword is used to identify the statement or action you are attempting to perform on the database. Other keywords include INSERT, DELETE, and UPDATE. More on these later. * or field names—The asterisk or names of the fields tell the statement which columns you want to extract data from. In this case, the asterisk means "all fields." FROM—The FROM keyword identifies which table to extract the data from. The FROM keyword is required with all SELECT statements. Table name(s)—The table name from which you want to extract the data. The following example extracts all records from your EmployeeStore table: SELECT * FROM EmployeeStore The preceding statement uses two keywords—the SELECT keyword and the FROM keyword—to extract all records from the EmployeeStore table. The previous statement would produce the following results (some fields have been excluded in order to fit on the page): ItemID ItemName Cost Quantity 1 Vecta Corp Shirt $12.99 100 2 Vecta Corp Hooded $29.99 100 3 Vecta Corp Longsleeve $19.99 100 4 Vecta Corp Polo $23.99 100 5 Vecta Corp Sticker $1.99 100 6 Vecta Corp Mousepad $1.99 100 7 Vecta Corp Coffee Mug $1.99 100 8 Vecta Corp Water Bottle $9.99 100 Selecting Certain Fields If you did not want to select all the fields in the database table, you could modify the field names to include only the fields that you wanted. SELECT ItemID, ItemName, Cost FROM EmployeeStore Notice that the preceding statement retrieves the data only from the ItemID, ItemName, and Cost fields. The preceding query produces the following results: ItemID ItemName Cost 1 Vecta Corp Shirt $12.99 2 Vecta Corp Hooded $29.99 3 Vecta Corp Longsleeve $19.99 4 Vecta Corp Polo $23.99 5 Vecta Corp Sticker $1.99 6 Vecta Corp Mousepad $1.99 7 Vecta Corp Coffee Mug $1.99 8 Vecta Corp Water Bottle $9.99 Notice that in this case, the ItemDescription and Quantity columns are left off. You could also modify the statement in an effort to retrieve the same information in a different order. For example, we could switch the field names by placing ItemName in front of ItemID, like this: SELECT ItemName, ItemID, Cost FROM EmployeeStore This code would give the following result: ItemName ItemID Cost Vecta Corp Shirt 1 $12.99 Vecta Corp Hooded 2 $29.99 Vecta Corp Longsleeve 3 $19.99 Vecta Corp Polo 4 $23.99 Vecta Corp Sticker 5 $1.99 Vecta Corp Mousepad 6 $1.99 Vecta Corp Coffee Mug 7 $1.99 Vecta Corp Water Bottle 8 $9.99 Selecting Unique Data The information in the EmployeeStore table contains duplicate values. As you can see, we have three items in our table that are priced at $1.99. If someone wanted to know about the unique variety of prices in our database, we would have to modify the statement to produce distinct results. The DISTINCT keyword can be used before the Cost field in this case to extract from the table only unique instances of data contained in that field. SELECT DISTINCT Cost FROM EmployeeStore The preceding statement would produce the following result: Cost $12.99 $29.99 $19.99 $23.99 $1.99 $9.99 As you can see, in this case, all cost information is displayed, but the results are limited to unique price instances. $1.99 is listed only once rather than three times. Clauses Clauses are portions of SQL that allow for further refinement of the query or additional work that must be accomplished by the SQL statement. The following clauses are covered in this section: The WHERE clause The ORDER BY clause The GROUP BY clause The WHERE Clause The WHERE clause is used in conjunction with the SELECT statement to deliver a more refined search based on individual field criteria. This example could be used to extract a specific employee based on a name: SELECT * FROM Employees WHERE Name = 'Ada' Notice that the selection is made only when a certain criteria is true. If a record with the name of Ada did not exist, it wouldn't return anything. But what if we had more than one Ada in the database? You could refine your search even further by using the AND operator: SELECT * FROM Employees WHERE Name = 'Ada' AND Phone = '5555551111' In this case, even if two Adas were listed in our database, we can assume that they don't have the same phone number. In this situation, the query returns one result (assuming, of course, that the two Adas aren't roommates). The ORDER BY Clause The ORDER BY clause provides you with a quick way of sorting the results of your query in either ascending or descending order. Consider the following table of information: EmployeeID Name Email 1 Cammy cammy@vectacorp.com 2 Ferris ferris@vectacorp.com 3 Ada ada@vectacorp.com 4 Dave dave@vectacorp.com 5 Agnes agnes@vectacorp.com If you selected all the records by using a SELECT all statement (SELECT *), it would return all the results, ordering them based on the value in the EmployeeID field: 1 through 5. Using the SELECT statement with an ORDER BY clause allows you to sort based on a different field name: SELECT * FROM Employees ORDER BY Name The preceding statement would return results in the following order: EmployeeID Name Email 3 Ada ada@vectacorp.com 5 Agnes agnes@vectacorp.com 1 Cammy cammy@vectacorp.com 4 Dave dave@vectacorp.com 2 Ferris ferris@vectacorp.com You can also order by multiple columns by adding a comma after the field name and entering a second field name: SELECT * FROM Employees ORDER BY Name, Phone In this case, all records with identical Name fields are sorted by phone. Tip You might decide to sort the results of your query in either ascending or descending order. When this is the case, you can use the ASC and DESC keywords preceding the field names as follows: SELECT * FROM Employees ORDER BY Name, Phone DESC The GROUP BY Clause When a query statement includes a GROUP BY clause, the SELECT statement for that query can list functions while operating on groups of data values in other columns. For example, data within the Orders table could look similar to the following table: OrderID EmployeeID ItemID Quantity 1 1 2 2 2 1 4 4 3 3 8 4 4 4 7 2 5 5 2 2 6 5 7 1 If you wanted to retrieve the total number of orders that were received, you could run the following query: SELECT Count(Quantity) AS NumberOfOrders FROM Orders The result would return the following: NumberOfOrders 6 In this case, we're exploring two unique concepts. First, we're selecting a count, using the built in Count function to return a total number of orders for the Quantity column. Second, we're using the AS keyword to create a virtual field called "NumberOfOrders." This gives us a total count of orders and stores that number (6) temporarily within a virtual field called NumberOfOrders. You could use the GROUP BY clause in this instance to group the orders by EmployeeID as follows: SELECT EmployeeID, Count(Quantity) AS NumberOfOrders FROM Orders GROUP BY EmployeeID The result would be as follows: EmployeeID NumberOfOrders 1 2 3 1 4 1 5 2 The result is based on the fact that employees 1 and 5 made two orders each while employees 3 and 4 made one order each. The INSERT Statement Collecting information from your users is not uncommon and, in most cases, it is a necessity. When you collect information such as registration information, you're not querying data, but rather you're inserting data into the database. In our Vecta Corp example, for instance, we'll create an Admin page that allows administrators to insert new employees into the database. To illustrate this point, consider the Employees table and some of the fields that make it up: Field Name Date Type EmployeeID AutoNumber DepartmentID Number Name Text Username Text Password Text Email Text Phone Text Headshot Text BillingShippingAddress Text BillingShippingCity Text BillingShippingState Text BillingShippingZip Text You could easily insert a new record into the Employees table using the following INSERT statement: INSERT INTO Employees (DepartmentID, Name, Username, Password, Email, Phone, Headshot, BillingShippingAddress, BillingShippingCity, BillingShippingState, BillingShippingZip) VALUES (1, 'Zak', 'zak', 'zak', 'zak@modulemedia.com', '5555555555', 'Images\head_zak.gif', '555 Sample St.', 'San Diego', 'Ca', '92115') The preceding statement inserts all the values you specified into the proper columns within the Employees table. The INSERT keyword generally uses the following elements: INSERT—The INSERT keyword is used to identify the statement or action you are attempting to perform on the database. INTO—The INTO keyword specifies that you are inserting something into a specific table. Table name—The name of the table into which you want to insert the values. VALUES—The actual values to be inserted. You could also use the SELECT statement within the INSERT statement to literally copy information from one table to the other: INSERT INTO Transactions (EmployeeID, Name, Email) SELECT EmployeeID, Name, Email [...]... properly defined in Dreamweaver, including the appropriate server-side technology you plan to use in the Testing Server category Connecting to a Data Source Step one in working with dynamic data in Dreamweaver is to properly define a website This important step establishes a connection between Dreamweaver and the files on your computer Aside from that, however, it also allows you to tell Dreamweaver what... you've learned how to write queries on your own But how does Dreamweaver use those queries to extract data from the database? For the most part, you can construct your queries in Access, copy the SQL code, and then paste it into the Recordset dialog (covered in the next chapter) Even better, Dreamweaver allows you to use saved queries directly from Dreamweaver For instance, if you wanted to create a complex... for the defined site This process is important because Dreamweaver must configure its interface according to the server-side technology you pick The second step in working with dynamic data is to establish a connection between Dreamweaver and your data source Numerous methods exist for connecting your web applications to your data sources (in Dreamweaver) , including the following: DSN Connection (supports... panel to help you interact with your dynamic web pages easily in Dreamweaver Starting to get excited? Good! This is where the previous 23 chapters begin to come together to form web applications As you've done with the rest of the chapters in this book, you can work with the examples in this chapter by downloading the files from www.dreamweaverunleashed.com Remember, you'll want to save the files for... ASP.NET, ColdFusion, and PHP in Dreamweaver Then you saw how databases such as Access, SQL Server 2005 Express Edition, and MySQL can serve as a backbone for data in your organization You learned about the various databases, what tables, columns, and rows are, and how to take existing databases and attach/restore them in your database management system for use within Dreamweaver Finally, you reviewed... this point is how to take all those foundation-level concepts and bring them together using Dreamweaver to create a truly dynamic database-driven page That's where this chapter comes in In this chapter, we'll take all the concepts you've learned up to this point and put them into practice You'll see how to connect Dreamweaver to your specific database using DSN and DSN-less connections Next you'll learn... Dreamweaver allows you to use saved queries directly from Dreamweaver For instance, if you wanted to create a complex join, you could create the statement in Access, save the query, and then use the query from Dreamweaver More on this in the next chapter Generating Queries with Relationships The true power in the Query Editor is that it can generate those complex statements with relationships that everyone hates... & ' ' & LastName AS Name FROM Employees Note You might have noticed that we've been using single quotes in every SQL statement The reason for this is simple: When you construct your SQL statements in Dreamweaver, the server-side language encloses the entire statement in double quotes For the statement to be valid, strings within a SQL statement must be enclosed within single quotes Adding the space... Data Source Using a DSN As mentioned in Chapter 20, "Introduction to Web Applications," to communicate with database data, a bridge of communication must be established between the web application in Dreamweaver and the actual data source itself This bridge of communication is handled through a Data Source Name (DSN) To understand the concept of DSN is to understand how applications connect to database . chapters, you'll learn just how easy Dreamweaver makes it to extract from, insert into, update within, and delete information from your database. Although Dreamweaver provides a simple process. chapters, you'll learn just how easy Dreamweaver makes it to extract from, insert into, update within, and delete information from your database. Although Dreamweaver provides a simple process. eventually build will have a direct impact on how complex your use of a data-access language will be. Dreamweaver provides a simple and easy-to-use process for commonly used data extraction and filtering

Ngày đăng: 01/07/2014, 19:20

TỪ KHÓA LIÊN QUAN