Archive for July, 2007

Chapter 10 . Databases And Data 235 MySQL

Tuesday, July 31st, 2007

Chapter 10 . Databases And Data 235 MySQL chooses Staticor Dynamictable formats automatically when you create the table. The Compressed table format must be created manually through the use of the myisampack utility. Static format The Static table format is the default and is used when there are no variable- length column types in the table such as VARCHAR or BLOB. If variable-length columns are used, MySQL will choose the Dynamic format for the table. An example of a table definition looks like this as follows: CREATE TABLE example (id int(5) NOT NULL PRIMARY KEY, name char(25), title char(20) ); In the preceding example table, all columns are fixed length as shown by the SHOW TABLE STATUS statement in Figure 10-3. Figure 10-3: The SHOW TABLE STATUS command reveals that the table is in Fixed row format. Static tables have two advantages: . With the exception of volatile-memory table types such as HEAP, the Static table format is the fastest of the three MyISAMoptions because its columns are a uniform size. For example, a CHARcolumn is padded with extra whitespace characters to bring the column up to the defined size; a VARCHARcolumn is not padded with extra characters. Since the column is always the same size, MySQL can sort through the data quicker as it knows that the column is a constant length regardless of the size of the data held within the column. . Padding of fields to the same size makes Static tables safer. The repair utility myisamchk can easily predict the boundaries of columns in a row.
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

234 Part II . SQL Essentials Figure 10-2 (My space web page)

Tuesday, July 31st, 2007

234 Part II . SQL Essentials Figure 10-2 shows the output of the mysqladmin variables command on a server where both the BerkeleyDBand InnoDB tables enabled. Note Figure 10-2: The mysqladmin variables command on a server with both BerkeleyDB and InnoDB tables enabled MyISAM The default table type for tables created in MySQL is MyISAM. The MyISAM table type is an extension of the ISAM table type. The MyISAM table type will eventually replace the ISAMtable type. In a future version of MySQL, the ISAM table type will no longer be offered. MyISAM uses a B-tree index type and compresses indexes whenever possible. For string-based indexes such as those on CHARand VARCHAR columns, MyISAM tables space-compress the index. To use compressed numeric-based indexes add PACK_KEYS=1 in the process of creating the table. Tables can be damaged by a system crash, a crash of the MySQL server, or any number of unforeseen events. If queries fail to return complete results or other unexplained errors occur, the table may need repair. Corrupt or broken MyISAM tables can be repaired with the myisamchk command. Cross- Reference Chapter 13 shows how to repair broken tables and solve other MySQL problems. There are three table formats for MyISAM tables: . Static . Dynamic . Compressed
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

Web hosting directory - Chapter 10 . Databases And Data 233 .

Monday, July 30th, 2007

Chapter 10 . Databases And Data 233 . If you installed MySQL from a binary version, you may or may not have transactional tables included. The MySQL-MAX version includes both InnoDB and BerkeleyDB. Some MySQL versions specific to flavors of Linux such as Debian include BerkeleyDB. Cross-Chapter 2 reviews the advantages of transactional and non-transactional tables. Reference To determine which table types your server supports, you can use the mysqladmin variables command. Tip Running the mysqladmin variables command outputs quite a bit of information so you may need to pipe the output to a pager such as more or less. Figure 10-1 shows the output for the command mysqladmin -p variables. I check for the lines that indicate whether BerkeleyDB and InnoDB tables are enabled. Figure 10-1 shows that only BerkeleyDB is available on this server. Therefore, I must use one of two approaches to choosing a table type: . I can choose BerkeleyDB. . Since non-transactional tables are available by default I can choose non- transactional tables, such as ISAM MyISAM HEAP Figure 10-1: Using the mysqladmin -p variables command to determine whether InnoDB or BerkeleyDB tables are supported
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

232 Part II . SQL Essentials (Web hosting solutions) Tip All

Monday, July 30th, 2007

232 Part II . SQL Essentials Tip All MySQL table types store data but there s usually a best type for any application. This section examines the table types supported in MySQL. With a solid understanding of the available table types, you re better equipped to choose the correct table type for your application. MySQL table types The six types of MySQL tables are best considered as three groups for the sake of compatibility: . Non-transactional tables. For many applications, non-transactional table types will be sufficient and will use fewer resources than transactional tables. For example, an online catalog, customer database, application database, and many other applications can utilize non-transactional tables successfully. The default table type in MySQL is the non-transactional MyISAM type. MyISAM is the table type of choice for nearly all applications. The three non-transactional table types are ISAM HEAP The HEAPtype is stored in volatile memory. If you are using a HEAPtable type and MySQL crashes or is shut down, all data in the table is lost! However, the HEAP table type is fast, making it a good choice for temporary tables. MyISAM Based on the ISAMtable type, MyISAMis the default for MySQL. . MERGE tables. The MERGE table type is a special extension of the MyISAM table. . Transaction-safe (transactional) tables. Transactional tables can combine statements and then commit or roll them back if some fail. Transactional tables are much safer in the event of MySQL or system crashes. These two table types are InnoDB BerkeleyDB The table types you can use depend on the version of MySQL installed on your server. Some table types weren t available in earlier versions of MySQL. Further, the tables available follow these general rules: . If you compiled MySQL from source code, you had the option to choose table types during the compilation process.
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.

10 1010 CHAPTER Databases and Data …. Adatabase

Monday, July 30th, 2007

10 1010 CHAPTER Databases and Data …. Adatabase is primarily a tool for organizing data into an accessible and usable form. That may seem obvious, but some of questions I m asked most frequently about are the brass-tacks of organizing data in MySQL database choosing the right table type, importing and exporting data, and using the mysqladmincommand to diagnose database problems correctly. Choosing the right table type is important; different applications may benefit from particular table types. Importing data into MySQL from other applications (such as Microsoft Access or Oracle) is a frequent task facing administrators migrating to MySQL. Finally, using the mysqladmincommand successfully is an important part of working with a MySQL server. This chapter examines all these subjects in detail. Choosing the Right MySQL Table Type A table type is one of various sets of characteristics that you can apply to a database table in MySQL usually for a specialized purpose, even though the appearance of MySQL tables may be similar from type to type. Just as you could use a kitchen table to perform surgery, or a picnic table as a desk, you could use a MySQL table for a purpose other than that for which it s designed but why? In This Chapter Introducing the MySQL table types Fine-tuning the syntax when using the mysqladmin command Exporting data from MySQL databases Importing data into MySQL databases ….
Check Tomcat Web Hosting services for best quality webspace to host your web application.

230 Part II . SQL Essentials The DELETE

Sunday, July 29th, 2007

230 Part II . SQL Essentials The DELETE statement has two versions. The first version of the DELETE statement simply deletes from one table. The second version of the DELETEstatement enables deletion from multiple tables. I ll show a syntax example or two for each type of DELETE. DELETE FROM example1 WHERE ID = 1; DELETE FROM example1 ORDER by ID LIMIT 1; DELETE example1,example2 FROM example1,example2,example3 WHERE example1.ID = example2.ID AND example2.ID = example3.ID; In the last of these examples, any matching rows are deleted from the example1 and example2 tables only. Showing my true System Administrator colors, I admit that my favorite action is performing deletes. Few ways of starting a day are more rewarding than removing a few hundred thousand records. Summary MySQL includes a large number of commands and statements used for administration as well as performance tuning and informational purposes. These statements include the SHOW, DESCRIBE, and KILL. . MySQL also includes most ANSI92 compatibility in the Data Definition Language (DDL) statements. . MySQL extends the ANSI92 standard in some DDL statements. . As with DDL, MySQL features compatibility with most ANSI92 Data Markup Language (DML) statements. . Like DDL, MySQL extends the ANSI92 standard in the area of DML. …
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

Chapter 9 . SQL According to MySQL 229 (Web hosting e commerce)

Sunday, July 29th, 2007

Chapter 9 . SQL According to MySQL 229 Figure 9-57: A look at the product table prior to the UPDATE statements, the three UPDATE statements, and a look at the product table after the updates Delete The DELETE statement can be used to delete specific records or the entire contents of tables; its syntax is as follows: DELETE [LOW_PRIORITY | QUICK] FROM
[WHERE where_clause] [ORDER BY …] [LIMIT #] or DELETE [LOW_PRIORITY | QUICK]
[.*] [
[.*] …] FROM tablereferences [WHERE where_clause] I ll dispense with some syntactical commonalities among many of the DML statements. The LOW_PRIORITYkeyword causes the DELETE to wait until no other clients are using the table. The WHEREclause tells the DELETE statement which records to delete. The ORDER BY clause determines the order by which the DELETE will occur. The LIMITmodifier causes the DELETE to only delete the specified number of rows. Though not common to other DML statements, the QUICK modifier can assist to speed up certain DELETE statements.
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

Web server extensions - 228 Part II . SQL Essentials Figure 9-56:

Saturday, July 28th, 2007

228 Part II . SQL Essentials Figure 9-56: Using ORDER BY and HAVING to sort the results from queries Updating data with the UPDATE statement I ve been attempting to come up with a witty anecdote to begin this section and I cannot. It s certainly not that I don t like the UPDATEstatement or that I don t believe it is useful. The UPDATE statement is really simple and intuitive, with only a few options. The equally simple truth is that the UPDATE statement is for making changes to existing records in the database. Its syntax looks like this: UPDATE [LOW_PRIORITY] [IGNORE] tbl_name SET col_name1=expr1, [col_name2=expr2, …] [WHERE where_definition] [LIMIT #] As does INSERT, the UPDATEstatement includes the LOW_PRIORITYand IGNORE keywords and using these keywords has the exact same effects. The LOW_PRIORITY keyword tells the UPDATE statement to wait until no other clients are reading from the table. The IGNOREstatement causes any collisions in non-unique columns to be ignored (another similarity to the INSERT statement). As with the SELECT statement, you can use a WHERE clause in the UPDATE statement to modify or drill down to the records you want to update. If you don t include a WHERE clause, you update all the records in the table. Another important similarity to SELECT is that you can use the LIMITmodifier to limit the number of records affected by the statement. Syntax examples follow (with results in Figure 9-57): UPDATE product SET name = Van Halen - Balance WHERE ID = 1; UPDATE product SET cate_ID = 1 WHERE cate_ID = 2 LIMIT 1; UPDATE product SET price = 19.99 , cate_ID = 2 WHERE ID = 2;
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

Chapter 9 . SQL According to MySQL 227 (Web hosting services)

Saturday, July 28th, 2007

Chapter 9 . SQL According to MySQL 227 Frequently I have to test a SELECT statement. For example, I might have the WHERE portion of the statement wrong, or a typo may crop up elsewhere in the statement. I also frequently work with fairly large tables that hold millions of records. Thus the LIMIT keyword has helped me countless times. Using LIMIT, I can set the SELECT statement to only return a subset of the results, thus potentially saving me from running a large and long query on a huge table. Figure 9-55: The results from some mathematical grouping functions Looking at one of the previous COUNT examples, if you wanted to order the results you could use the ORDER BYfunction. The ORDER BY function can sort the results in either ascending or descending order through the use of the ASC or DESCkeywords. In addition, you can use the HAVINGkeyword for even further parsing of results from a GROUP BY clause. I ll expand on some earlier examples here (and show the results in Figure 9-56): SELECT user,COUNT(user) FROM user GROUP BY user ORDER BY COUNT(user) DESC; SELECT user,COUNT(user) FROM user GROUP BY user ORDER BY user ASC LIMIT 3; SELECT user,COUNT(user) FROM user GROUP BY user HAVING user = suehring ;
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.

226 Part II . SQL Essentials I can (My web server)

Friday, July 27th, 2007

226 Part II . SQL Essentials I can show these functions best in the following examples; results are in Figure 9-54: SELECT COUNT(*) FROM user; SELECT COUNT(user) FROM user where host = localhost ; SELECT user,COUNT(DISTINCT user) FROM user GROUP BY user; SELECT user,COUNT(user) FROM user GROUP BY user; Figure 9-54: Examples of the COUNT function for grouping the results from a query The next set of examples comes from the ecommercesample database that I ve been working with in this chapter and throughout the book (results in Figure 9-55): SELECT AVG(price) FROM product; SELECT MIN(price) FROM product; SELECT MAX(ID) FROM manufacturer; SELECT SUM(price) FROM product;
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.