SQL statement Optimization principles, SQL statement optimization
Ways to improve query speed with data above millions:
1. Try to avoid using the! = or 2. To optimize the query, avoid full-table scanning as far as possible, and first consider establishing an index on the columns involved in the Where and order by.3.
The SQL statement for data deletion and the SQL statement for data deletion
No matter whether you are a new college student or a veteran who has been fighting in the software field for many years, as long as you mention the SQL statements used to delete data, it is easy to s
SQL statement and SQL statement
1 StringBuilder SQL = new StringBuilder ("SELECT * FROM t_customer WHERE 1 = 1"); 2/* 3*2. determine the condition to complete the append of the where clause 4 */5/* 6*3 to the SQL
Label:SET STATISTICS profile on: Displays the time, in milliseconds, that is required to parse, compile, and execute the query.SET STATISTICS IO on: Reports information about the number of scans per table referenced in the statement, the number of logical reads (pages accessed in the cache), and the number of physical reads (the number of times the disk was accessed).Set STATISTICS time on: Displays the result set after each query execution, represent
In this forum, I will talk about several ways to improve the efficiency when using LINQ to SQL.
(This forum will be updated constantly and everyone will learn and make progress together)
(A log attribute under the datacontext instance can be seen by setting this attribute. The SQL code generated by the LINQ statement will be used in the code below)
1. latency.
(
Group character merge SQL statement merge strings by a field (simple merge), SQL statement
Title: Merge strings by a field (simple merge)
Description: merges the following data into the value field by id.Id value-----------1 aa1 bb2 aaa2 bbb2 cccExpected results:Id value-----------------1 aa, bb2 aaa, bbb, cccThat is:
One: Executes the SQL statement, returning the number of rows affected In MySQL, if there is no effect, then the number of rows returned is-1, SQL Server has not been tested Usingnew Mydbcontext ()) { ctx. Database.executesqlcommand ("UPDATE person SET Name = ' Michael ' WHERE PersonID = 1");}Two: database.sqlqueryThis is exactly the ienumerableThis is the Exe
SQL statement used in sqls. SQL statement
Sqlite has been used for many queries recently, including table connection queries. Record it to avoid forgetting it!
1. First sort by time and then select the first 10:
Select * from MyBill order by createTime desc limit 10;
2. Sum of price:
Select sum (price) as sum from MyB
SQL statement Dual Loop, SQL statement
The shunxu field in Table j_wenzhang_aps201503 is null. Now you want to update the shunxu Field Based on lanmu_id and qishiye.
1. If the shunxu field is auto-incremented, there are no duplicates, And the lanmu_id is small, the shunxu is also small; the lanmu_id is the same, the
Required SQL statement (4) data deletion and update, SQL statement
1. Delete
1) delete recordsDelete from table name where id = 'xx'
2) Delete all data and return to the initialization Id field.Truncate table name
3) differences between delete and truncateA. truncate enables seeds to return to the initial value.B.
|+-----+--------+------+-------+------------+--------------+--------+-------+19. Enquiries are the names, ages, faculties and examinations of students in Hunan province and their scoresMysql> SELECT Student.id, name,sex,birth,department, address, C_name,gradeFrom student, score-WHERE address like ' Hunan% ' andstudent.id=score.stu_id;+-----+------+------+-------+------------+--------------+--------+-------+|ID |name |sex |Birth |Department |Address |C_name | Grade |+-----+------+------+-------+
SQL statement | description of connector usage, SQL statementI. | role
| Indicates splicing, such as 'A' | 'B' is equivalent to 'AB'Ii. | example:
Generate select statements in batches
Select 'select * from' | tname | ';' from tab t where t. tname like't _ P _ % ';
For example:
Then you can copy these select statements to the document !!Iii. Instances
| I
"A project of Php+mysql"
There is a user, username is admin, password is admin.
The query statements are:
$sql="select * from table_project where a_username='{$username}' and a_password='{$password}';";
Then query:
$res=mysql_query($sql);……省略
Because of preventing SQL injection, I wanted to escape before the SQL
PL/SQL script language value assignment statement syntax table and record comply with the type usage, select the statement if else usage anonymous block (1), assign value statement syntax PL/SQL values use: = "=" some rules need to be observed in the comparison operator valu
PHP fails to execute the SQL statement, but the current problem that the same statement can be executed in MYSQL is that some tables in the same database can be queried, and some tables cannot be queried. However, these statements can be normally executed in mysql ------ solution ------------------ check in one case, LZ can be combined into an
* From handle B where B. handleid = 1) Then min (handleid) + 1 else 1 end) as handleid from handle where not handleid in (select. handleid-1 from handle)
A problem with an SQL statement: column and column ConversionSelect * From v_tempThe preceding view result is as follows:User_name role_name-------------------------System AdministratorFeng AdministratorFeng usersTest UsersThe result is as follows:User_n
Use SQL statement 1 in ASP: select statement
Source: dns99.cn
There are so many SQL products that you may have to worry about. However, if you want to use ASP and SQL at the same time, you may feel dizzy. MySQL,
The three methods in the connection interface can be used to create instances of these classes. These classes and their creation methods are listed below:
(1) Statement-created by the createstatement method. The statement object is used to send simple SQL statements.(2) preparedstatement-created by the preparestatement method.(3) The preparedstatement object is
SQL GROUP BY statement, sqlgroupby statement
A group by statement is often required for Aggregate functions (such as SUM.Group by statement
The group by statement is used in combination with the aggregate function to GROUP result
Write in front: This article only for the IO causes MySQL performance problem localization, other such as CPU, mysql parameter configuration, program itself and other issues need to be further supplemented.Background: A SQL Build Table statement was run for 15 seconds: (STEP1:Open profiling
SET profiling=1;
Shut down
SET profiling=off;
Find the
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.