当前位置:网站首页>Bi-sql stored procedure (I)

Bi-sql stored procedure (I)

2022-06-25 23:33:00 Powerbi white tea

stored procedure ( One )

stored procedure , Can be said to be SQL The more important concept in , Basically, all data projects will involve this content .

Many interviews take place in the second round of technical interviews , It will also be mentioned , So what are stored procedures ?

Definition

  • Stored procedures are similar to C Functions in language

  • It can usually be used to perform administrative tasks or apply complex rules

  • Stored procedures can take parameters , You can also return the result directly

  • Stored procedures can contain data manipulation statements 、 Variable 、 Logic control statements, etc

White tea recently talked about stored procedures with her development partners , That's what he said :

stored procedure , You can think of it as a data set .

Can be called by an internal trigger , Can be called by external programs , It can also be called by other stored procedures .

grammar

SQL Server grammar :

CREATE PROCEDURE  Stored procedure name 
@PARAMETER  Parameter type 
......
AS
BEGIN
 Procedure statement 
END

Call stored procedure statement :

EXECUTE  Process name  

Using examples

Case data :

In the database of white tea machine, there is a database named “CaseData” The database of .

“Dim_Date“ Date sheet 、"Dim_Product" Product list 、"Fact_Sales" Sales fact sheet .

Example 1:

Create a TEST1 Stored procedure , The product name in the filtered products table is “ sunglasses ” The data of .

CREATE PROCEDURE TEST1
AS
BEGIN
SELECT * FROM Dim_Product WHERE ProductName=' sunglasses '
END

give the result as follows :

Let's try calling this stored procedure to see the result :

EXECUTE TEST1

give the result as follows :

Example 2:

Create a TEST2 Stored procedure , Store all data in the product table , And add parameters , So that subsequent conditional calls can be made .

CREATE PROCEDURE TEST2
@Product VARCHAR(20)
AS
BEGIN
SELECT * FROM Dim_Product WHERE [email protected]
END

give the result as follows :

The input name is “ masks ‘ Conditions , Let's call TEST2 stored procedure .

In terms of results , In line with our expectations .

actually , Stored procedures have a lot more , White tea is not introduced in detail , For example, what are the benefits of stored procedures , For example, the use of stored procedures to add loops , The usage of adding cursors to stored procedures, etc .

Later, white tea will be added slowly , There are some inaccuracies in the article , Please forgive me , White tea is also in the stage of just learning .

Take dreams as horses , Not to lose time , May we learn together , Common progress .

This is white tea , One PowerBI Beginners .

原网站

版权声明
本文为[Powerbi white tea]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206252021091750.html