1. Obtain the first row of data in the table
select top 1 * from Dept
2. display a specific row in the first row
select DeptNO,DeptName,Phone,Manager,Deputy,Remark from dept where parentID='3' order by case when deptNO='3' then 0 else 1 end
3. SQL nested Query
select a,b,c from tableD where a=(select a from tableD)
select * from table1 where field1 in (select field1 from table2 where field2 in
the table specified for that hint to be read-only in Gianpene.16, with Profiler to track the query, get the time required to query, find out the problem of SQL; Use the index optimizer to optimize indexes.17, notice the difference between Union and union all. UNION all good.18, pay attention to use distinct, do not need to use, it is the same as the Union will m
1. Convert time into a string:
Copy codeCode: convert (varchar, field name, 120) -------- yyyy-mm-ddhh: ss: mm0000
Convert (char (10), field name, 120) ------ yyyy-mm-dd
2If you are using the SQL Editor (a tool provided by Microsoft), you do not need to use function conversion to query the date. For example:SQL codeCopy codeThe Code is as follows: select * frominfowheredatatime> '
returned by the user or set rowcount to restrict the operation of the line
22, in the SQL2000 before, generally do not use the following words: "Is NULL", "23. Use Query Analyzer to view query plans for SQL statements and evaluate whether the analysis is optimized for SQL.
@ Ftech Is Not Null Begin If @ Sqlstr Is Not Null Set @ Sqlstr = @ sqlstr + 'And ftech =' + '' '' + @ Ftech + '' '' Else Set @ Sqlstr = 'Where ftech =' + '' '' + @ Ftech + '' '' End If @ Fsubject Is Not Null Begin If @ Sqlstr Is Not Null Set @ Sqlstr = @ sqlstr + 'And fsubject =' +'' '' + @ Fsubject + '' '' Else Set @ Sqlstr = 'Where fsubject =' + '' '' + @ Fsubject + '' '' End If @ Fjif Is Not Null Begin If @ Sqlstr Is Not
Select. *, B. * From OpenRowSet ('msdasql ', 'driver = {SQL Server}; server = 119.254.245; uid = sa; Pwd = abc123_kxr', mall_master.dbo.product) as a, kxr_products B -- where, tom is the remote server name, and stores is the table in the local database pubs. Note that if the number of records in the two tables is different, a table will generate completely duplicate rows, -- the number of rows in the table with the longest record set is insert into DB
Tags: art div isnull and format date color font query1. Time format is string type (query all record time 2017-11-03 if (! Strings.isnullorempty (StartDate)) {Querysql+=" andDo.enter_date_time>=To_date ('"+ StartDate +"','YYYY-MM-DD') ";
}
if (! Strings.isnullorempty (endDate)) {Querysql+=" andDo.enter_date_timeTrunc (To_date ('"+ endDate +"','YYYY-MM-DD')+1) ";
} 2. Get the time format in the background (e
Qian's lines: witness the miracle of the moment, we re-execute the previous query:From the above example, you can see the power of the indexed view, even if your query statement does not include the indexed view, the Query Analyzer will automatically select this view, which greatly improves performance. Of course, so powerful performance, only in
pages to find the appropriate results, while the former only scans each row in the table.The second part of the tutorial is described here. There will be a final article on how to write a better SQL query series, so stay tuned.Original link: http://www.kdnuggets.com/2017/08/write-better-sql-queries-definitive-guide-pa
Tags: param SQL query rate ATI query insert data bit check ESCThe debug code finds that the same method is called at the end of two operations. The incoming parameters are consistent and the query results are inconsistent. Directly say the cause of the problem: My two operations are AOP surround notification first get
often forget! Access In the recent writing Web program used the fuzzy query access, in the Acces write code how can not find records, later only up the original acess and SQL Server fuzzy query is a specialCondition: Lookup Table A in the Name field includes "B" in the recordCode in Access: 1 Select * from a where name like ' *b* '
can not find records, later only up the original acess and SQL Server fuzzy query is a specialCondition: Lookup Table A in the Name field includes "B" in the recordCode in Access:1 Select * from a where name like ' *b* ' SQL Server Query Analyzer codeSelect * from a where n
the Acces write code how can not find records, later only up the original acess and SQL Server fuzzy query is a specialCondition: Lookup Table A in the Name field includes "B" in the recordCode in Access: 1 Select * from a where name like ' *b* ' SQL Server Query Analyzer c
expression that is to be converted to a float or real data type can optionally contain an exponential symbol (E or E, followed by an optional + or – symbol, followed by a number).When you convert a character expression to a data type of a different size, values that are too long for the new data type are truncated, and SQL Server displays an asterisk (*) in the osql utility and SQL
You might want to query a previously executed statement during normal debugging. The following is a query history execution statement in sqlserver2008.SELECT TOP + --creation TimeQs.creation_time,--Query StatementsSUBSTRING(ST.text, (Qs.statement_start_offset/2)+1, (( CaseQs.statement_end_offset when -1 Then datalength(St.text) ELSEQs.statement_end_offsetEND -Q
considerations for improving query speed, but in many other cases, it is often necessary to repeatExperiment with different statements to get the best solution. The best way to do this, of course, is to look at the SQL language that implements the same function.Which run time is the least. However, the database assumes that the amount of data is very small, is less than the comparison. You can then use the
A
WHERE rownumber > page Size * (page-1
Description, Page size: Number of rows per page; pages: pages. When using, replace "page size" and "page size * (number of pages-1)" with numbers. Other scenarios: If you don't have a primary key, you can use a temporary table, or you can do it with scenario three, but the efficiency will be low. When tuning is recommended, the query efficiency increases with the prima
connections is much faster than looping nesting. From the principle of merging joins it is not difficult to imagine that merging connections first requires both parties to be orderly. And the condition of the join is equal to the number. Since two input conditions are already in order, it is not difficult to see why the merge join is only allowed to be equal to the join after a row is compared from each input set, equal returns, and unequal discards. We can see this principle from the icon in F
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.