--
Script used to obtain the connection information of the SQL Server server (based on the original shard creation and writing)
Declare@ Dbname sysname,-- The name of the database to be queried (empty for all). The connection information of all databases is queried by default.@ Brief deip bit-- Whether to display the IP address (0 NO, 1 Yes). This control is added because the IP address query is time-consu
Solution for slow SQL query caused by custom functions, function SQL
During the report process, one report queries the exchange rate of the corresponding currency, and the exchange rate is in another table, the condition for querying the exchange rate is to query the exchange rate of the previous month of the statist
An additional column of serial numbers is automatically added to the SQL statement query results, and an SQL column is automatically added.
Sqlserver
It can be implemented using the row_number function.
As follows:
SELECT *, row_number () OVER (order by score (column name) DESC) AS rank FROM score
The SQL
Distributed | data | database
/ * t-SQL code to implement distributed query of heterogeneous database using MS
exec sp_addlinkedserver ' ms_sql ', ', ' SQLOLEDB ', ' 172.18.9.20 'exec sp_addlinkedsrvlogin ' Ms_sql ', ' false ', NULL, ' Sa ', ' capec '/* Create a remote link for SQL Server to SQL Server database * *
ex
table [table name] Add field name the datetime default function increases the date Type field, where the function can be now (), date (), and so on, representing the default value (which is most commonly used, and other properties, which can be referenced by the following data type Delete field: ALTER TABLE [table name] Drop field name Modify size of variable-length text field: ALTER TABLE [table name] ALTER field name varchar (N) Delete table: drop tables [table name] Nbsp;
First SQL statementSelect CompanyName GSMC,ZB Zhibiao from Left Join T_companycode on T_GSNDZB.GSBH=T_companycode.companyidQuery Result:A second SQL statementSELECT min(CompanyName) GSMC,cast(round(sum(T_xstj.hsje)/10000,2) asNumeric -,2)) Ndje fromT_xstj Left JoinT_companycode onT_companycode.companyid=T_XSTJ.GSBHwhere DateDiff( YearSjgetdate())=0 Group byGsbhQuery Result:Statements that are merged int
Id = % d of the SQL query statement in PHP (recommended), SQL % d
Some SQL statements are written as follows:
'Select id FROM dbname WHERE xx_id = % d; ', $ bl ['student _ id']
"Xx_id = % d", here % d Refers to a decimal number (d means decimal ), the content of the decimal number is the following $ bl ['student _ i
Read Catalogue
Begin
How SQL Server looks for records
SQL Server Join method
More specific execution procedures
Index statistics: The choice of the query plan is based on
Optimizing View Queries
Recommended Reading-MSDN Articles
For SQL Server optimizations, tuning queries can be a
Read SQL Server query planRead Catalogue
Begin
How SQL Server looks for records
SQL Server Join method
More specific execution procedures
Index statistics: The choice of the query plan is based on
Optimizing View Queries
Recommended Reading-M
The more CPU and IO resources a query requires, the slower the query speed. Therefore, another way to describe the query performance tuning task is, the query command should be rewritten in a way that uses less CPU and IO resources. If the query can be completed in this way,
Enabling slow query log for tracking SQL Execution in MySQL and SQL log tracking in mysqlQuery slow query parametersShow variables like '% quer % ';
Slow_query_log (whether to record slow queries)
Slow_query_log_file (slow log file path)
Long_query_time (logs are recorded only when the specified time is
Usage scenarios:For example, you need to query all student numbers with scores greater than 95, separated by commas into a string, from the Student score table.To prepare the test data:CREATE TABLE score (ID int,score int)INSERT into score values (1,90)INSERT into score values (2,96)INSERT into score values (3,99)It is now necessary to query the result string "2,,3" with a single statement.The
the same, then the greater than and equals sign are the same)1.select gid,fariqi,neibuyonghu,reader,title from Tgongwen where fariqi> ' 2004-1-1 ' and fariqiSpents: 3280 milliseconds4. The date column will not slow down the query speed because there is a minute or seconds inputIn the following example, there are 1 million data, 500,000 data after January 1, 2004, but only two different dates, the date is accurate to the day, before the data 500,000,
1. SQL statements
Is a language
Meets ANSI standards
Keyword cannot be abbreviated
Use statements to control the definition information and data of tables in the database
SQL is the abbreviation of Structured Query Language (Structured Query Language. You can use SQL statem
Original: SQL query performance analysisOriginal source: http://blog.csdn.net/dba_huangzj/article/details/7623926The performance of SQL query directly affects the value of the whole database, which must be treated solemnly.SQL Server provides a variety of tools, and here's a simple introduction:First, 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.