Database Basics (exercises, stored procedures that define variables to query)

Source: Internet
Author: User
Tags stored procedure example

Exercises for defining variables:

Stored procedures:

Stored procedures (stored procedure) are sometimes referred to as sproc. Stored procedures are stored in a database rather than in a separate file, with input parameters, output parameters, and return values.

In a database, the process of creating stored procedures is the same as creating other objects, except for the AS keyword that it uses. The basic syntax for a stored procedure is as follows:

CREATE procduer| PROC <sproc name>

[<parameter Name>[schema.] <data Type>[varying][=<default value>][out [put]][,

[<parameter Name>[schema.] <data Type>[varying][=<default value>][out [put]][,

...]]

[With

recompile| encryption| [EXECUTE as {caller| Self| owner|< ' user name ';}]

[For REPLICATION]

As

<code>| EXTERNAL NAME <assembly name>.<assembly class>

Example stored procedure one:

Execute stored procedure method one:

Execute stored procedure method two:

As stated above, a stored procedure can define a return value.

Example:

To modify a stored procedure example:

Use a stored procedure to find examples of information in three tables:

Example:

Example two:

Example three:

Exercise one: The topic is as follows

Example of receiving using the return value:

Example of a method that simply uses the return value:

When creating a stored procedure, we can set it to have a default value.

Example:

Practice One: Enter a number to 1~n and

Exercise two: Enter the student number to see the total score of the students ' classes

Exercise three: Define a @count receive return value to see if it contains the student

Database Fundamentals (exercises, stored procedures that define variables to query)

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.