Tips for using SQL statements in the phpmysql database

Source: Internet
Author: User
When you use the groupby group for query, the default group is sorted, which may reduce the speed. adding orderbynull after groupby can prevent sorting 1. when you query by group by, the default group is sorted, which may reduce the speed. adding order by null after group by can prevent sorting. 2. in some cases, you can use a connection to replace subqueries. Because join is used, MySQL does not need to create a temporary table in memory. Select * from dept, emp where dept. deptno = emp. deptno; [simple processing method] select * from dept left join emp on dept. deptno = emp. deptno; [left outer join, more OK!] How to choose mysql storage engine myisam storage: if the table does not have high transaction requirements and is mainly query and add, we will consider using the myisam storage engine ., for example, the posting table and reply table in bbs. INNODB storage: high transaction requirements and important data are stored. we recommend that you use INNODB, such as order tables and account tables. question: What is the difference between MyISAM and INNODB? 1. transaction Security innodb supports Things 2. fast query and acceleration conditions and query of MyISAM 3. support Full-text index myisam4. lock mechanism 5. the foreign key MyISAM does not support foreign keys. INNODB supports foreign keys. (in PHP development, foreign keys are usually not set, and data consistency is usually ensured in the program) Memory storage. for example, if data changes frequently and does not need to be written into the database, memory is frequently queried and modified. u if the storage engine of your database is myisam, remember to perform fragment on a regular basis.

Example:


create table test100(id int unsigned ,name varchar(32))engine=myisam; insert into test100 values(1,’aaaaa’); insert into test100 values(2,’bbbb’); insert into test100 values(3,’ccccc’); 


We should define and sort out myisam


optimize table test100; mysql_query(“optimize tables "tbname”);  

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.