Grouping TOP data is a common query in the T-SQL, such as the student information management system to take out the first three students of each subject. Before SQL Server 2005, such queries are cumbersome to write and can be obtained only when
SQL Server cursor statement usage:Copy codeThe Code is as follows:-- Declare a cursorDECLARE MyCursor CURSORFor select top 5 FBookName, FBookCoding FROM TBookInfo // defines a cursor called MyCursor, which stores data after select-- Open a
Grandma's, why are we only three days in May? The weather in May is the most suitable for traveling, but we cannot afford these tough IT guys.As soon as I arrived at the company, the project manager found the development leader, saying that our
As we all know, the error messages of SQL statements can be found in the sys. messages table.
For example:
If the execution statement is in try... catch, we can get the error information through the following methods. The SQL statement is as
Copy codeThe Code is as follows:-- SQL Server 2000SELECT a. name AS field name, CASE WHEN EXISTS(SELECT 1FROM sysobjectsWHERE xtype = 'pk' AND parent_obj = a. id AND name IN(SELECT nameFROM sysindexesWHERE indid IN(SELECT indidFROM sysindexkeysWHERE
Char (n) is a fixed-length format. The field in the format of char (n) occupies a fixed width of n characters. If the actual length of the stored data exceeds n, the excess data is truncated, if the length is less than n, it will be filled with null
ISNULL
Replace NULL with the specified replacement value.
SyntaxISNULL (check_expression, replacement_value)
ParametersCheck_expression
Whether the expression is NULL is checked. Check_expression can be of any type.
Replacement_value
The expression
Copy codeThe Code is as follows:Declare @ t varchar (255), @ c varchar (255)Declare table_cursor cursor for select a. name, B. nameFrom sysobjects a, syscolumns B, policypes cWhere a. id = B. id and a. xtype = 'U' and c. nameIn ('Char ', 'nchar',
About with ties
If with ties is generally used in combination with Top and order by, the extra return values of the last data record will be queried (explanation: if the order by parameter is used to sort TOP n (PERCENT) the previous n (pencent)
1. the SQL insert statement obtains the auto-generated incremental ID value.Copy codeThe Code is as follows:Insert into Table1 (Name, des, num) values ('ltp ', 'thisbest', 10 );Select @ identity as 'id' 2. Implement 1 or 0 to show as a male or
Misunderstanding #25: Multiple misunderstandings about fill FactorsAll are errors.25a) Fill Factor always existsNo, it can be seen through Books Online (Translator: I did not find this sentence in the new version of the BOL ):Important:The fill
SQL statements are case-insensitive by default, so the statement:SQL codeSELECT * FROM RecEngineBizInfo WHERE RecEngineBizName = 'qq'AndSQL codeSELECT * FROM RecEngineBizInfo WHERE RecEngineBizName = 'qq'The results are the same.The script to check
TFP is used for daily project updates in the company, and Remote Desktop Management is generally used for server maintenance. Therefore, you often log on to the server. However, for some reason, after logging on to the server, the account is not
1 annotatorAnnotation is a text string that is not executed in the program code. It is a description of the program, which can improve the readability of the program and make the program code easier to maintain, it is usually embedded in a program
1. Statement block (BEGIN... END)Statement block Syntax:BEGINENDBEGIN... END is used to set a statement block. Multiple Transact-SQL statements can be encapsulated to form a statement block. during processing, the entire statement block is
Use NOLOCK and READPAST in the query statementWhen handling a database deadlock exception, it is recommended to use NOLOCK or READPAST. Some technical knowledge about NOLOCK and READPAST:For industries that strictly require transactions such as
Take the first 20 to 30 queries as an example. The primary key name is id.Method 1: perform a regular check first and then perform a reverse check. Select top 10 * from (select top 30 * from tablename order by id asc) A order by id descMethod 2: Use
Common misunderstandings include:1. dynamic SQL concatenation is not allowed with only ado.net.2. There are several dynamic parameters, and the repeated amount of code becomes the number of combinations of these parameters. The more dynamic
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.