Use of SQL SERVER: exceute statement: It is too powerful

Source: Internet
Author: User
Tags scalar

The most common usage of an execute statement is to execute the stored procedure. However, he still has more powerful and extensive use methods.

1. Execute the Stored Procedure

Stored Procedure names support four object names: nominal value, variable

The passed parameters can be: literal value, variable, default value; input or output

Can obtain the return value of the stored procedure. If the stored procedure does not have a return statement, 0 is returned! If the stored procedure returns other types and other values, it must be a value that can be converted to the int type!

The same series of stored procedures can be executed.

Force re-compile the stored procedure during execution: With recompile

 

2. Execute the Function

Similar to executing a stored procedure.

Note: At this time, the function call cannot have parentheses ()!

Can obtain any scalar return type and value of the function, scalar!

 

3. Execute a dynamic SQL string

Execute statement must contain parentheses ()

SQL string can be any valid SQL string: literal value, variable

The execution context can be changed: As {login | user} = 'name'

 

4. pass-throug string: This function makes execute extremely convenient and powerful !!!!!!!!!!!!!!!!!!!!!!!!!

Similar to a dynamic SQL string, a string can contain "?" Indicates variables that can be transmitted to each other.

The replace variable can be the literal value or variable. Such as "? If output is of the output type, the replacement variable must be a variable.

After sqlsever2005, You can execute it on the connection server!

 

Execute syntax

Execute a stored procedure or function
[ {Exec | execute} ]
{
[@ Return_status =]
{Module_name [; number] | @ module_name_var}
[[@ Parameter =] {Value
| @ Variable [Output]
| [Default]
}
]
[,... N]
[With recompile]
}
[;]

Execute a character string
{Exec | execute}
({@ String_variable | [N] 'tsql _ string'} [+... n])
[As {login | user} = 'name']
[;]

Execute a pass-through command against a linked server
{Exec | execute}
({@ String_variable | [N] 'COMMAND _ string'} [+... n]
[{, {Value | @ variable [Output]} [... n]
)
[As {login | user} = 'name']
[AT _ SERVER_NAME]
[;]
Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.