In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
How to use control statements in SQL Server? for this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.
1. BEGIN (sentence). The syntax of the END statement block is as follows: BEGIN ENDBEGIN... END is used to set a statement block. Multiple Transact-SQL statements can be encapsulated to form a statement block. When processing, the whole statement block is regarded as a statement. BEGIN... END is often used in conditional statements, such as IF. In the ELSE or WHILE loop. BEGIN... END statements can be used in nests.
two。 Judgment statement (IF … ELSE) usually the computer executes the statements in the program sequentially, but in many cases, the order in which the statements are executed and whether or not to execute depends on the intermediate results of the program, in which case, a judgment must be made based on the value of a variable or expression to decide which statements to execute or not to execute. At this point, you can take advantage of IF. The ELSE statement makes a judgment and chooses to execute a statement or block of statements. The syntax of the judgment statement is as follows: IF [ELSE [conditional expression]]
3 Detection statement (IF … EXISTS) IF... The EXISTS statement is used to detect the existence of data, regardless of the number of rows that match it. For existence detection, use IF... EXISTS is better and more efficient than using COUNT (*) > 0, because the server stops executing the SELECT statement as soon as the first matching row is found. The syntax of the detection statement is as follows: IF [NOT] EXISTS (SELECT query statement) [ELSE]
4. Multi-branch judgment sentence (CASE … WHEN) CASE... The WHEN structure provides a better performance than IF. ELSE structure has more choices and judgment opportunities, and it can be easily used to achieve multi-branch judgment, thus avoiding multiple IF. ELSE statements are used in nests. Multi-branch judgment statement CASE. There are two formats for WHEN syntax: the first format syntax is as follows: CASE WHEN THEN WHEN THEN [ELSE] END the second format syntax is as follows: CASE WHEN THEN WHEN THEN [ELSE] END
5 Loop statement (WHILE) Loop statement can set conditions for repeated execution of SQL statements or statement blocks, as long as the specified condition is TRUE (the condition holds), the statement is repeated. The syntax of the loop statement is as follows: WHILE BEGIN [BREAK] [CONTINUE] [command line or block] END
6 jump statement (GOTO) use the jump statement GOTO to change the process of program execution so that the program jumps to the specified program line marked with an identifier, and then continues to execute. The identifier as the target of the jump can be a combination of numbers and characters, but it must end with ":". The syntax of the jump statement is as follows: GOTO identifier:
7 return statement (RETURN) the return statement is used to end the execution of the current program and returns to the last program or other program that called it, with a return value specified in parentheses. The return statement enables the program to unconditionally exit from batches, stored procedures, and triggers, and no longer executes any statements after RETURN. The syntax of the return statement is as follows: RETURN ([integer value])
8 defer the execution of the statement (WAIT … The FOR) WAITFOR statement is used to temporarily stop program execution until the set wait time has passed or the set time has expired. The time must be DATETIME type data, the delay time and time are in the format of "HH:MM:SS", the date cannot be specified in the WAITFOR statement, and the time length cannot exceed 24 hours. The syntax of the deferred execution statement is as follows: WAITFOR {DELAY | TIME} sql_statement DELAY: it is used to set the waiting interval, up to 24 hours. TIME: used to set the time to wait for the end.
Sql_statement: the SQL operation statement to continue execution when the set wait time has expired or the set time has expired.
This is the answer to the question about how to use control statements in SQL Server. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.