SQL Server stored procedure Basic syntax

Source: Internet
Author: User

First, define variables

1, simple assignment 2, using the SELECT statement to assign a value of 3, using the UPDATE statement to assign a value

DECLARE @a int declare @user1 nvarchar (50) declare @user3 nvarchar
Set @a=5 Select @user1 = ' Zhang San ' update st_user set @user3 = Name where id=1
Print @a print @user1 print @user3

declare @user2 nvarchar (50)

Select @user2 = Name from St_user where id=1

Print @user2

Second, create a temporary table

CREATE TABLE #DU_User1
(
[ID] [int] not NULL, 1 inserts a data into the staging table insert into #DU_User1 (Id,name,[password]) VALUES (100, ' temporary ', ' 321 ');
[Name] [nvarchar] (5) Not NULL, 2 query data from St_user, populate to newly generated temporary table select * into #DU_User2 from St_user where id<8
[Password] [nvarchar] (max) NULL, 3 queries and union two temporary tables select * FROM #DU_User2 where id<3 union select * FROM #DU_User1
); 4 Delete temporary table drop table #DU_User1

SQL Server stored procedure Basic syntax

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.