SlideShare a Scribd company logo
1 of 17
12 SQL SERVER: SQLFUNCTIONS AND PROCEDURES
SQL Procedures What is an SQL Procedure? 	An SQL Procedure contains a  group of sql statements which solve a common purpose.  Syntax: Consider a simple SQL Procedure: Create proc printProcedure As Print ‘Hello World’ go Create proc <procedureName> As …. Statements… Print is a command in SQL Server 2008. It is used to print a string on the screen. NOTE: The SQL Procedures that we learn here are stored in the system by the DBMS. They are hence known as stored procedures
Altering stored procedures How to alter a SQL stored procedure? 	A Stored procedure can be altered using the alter proc command. Syntax: Consider a simple SQL Procedure: Alter proc printProcedure As Print ‘New Hello World’ go Alter proc<procedureName> As …. New Statements…
Executing Procedures The Main advantage of using a stored procedure is its reusability, i.e., a procedure can be called any time that it needs to be executed. An SQL procedure can be executed using the exec command: Exec <ProcedureName> Example:  Create proc printProcedure As Print ‘New Hello World’ Go Exec printProcedure OUTPUT: New Hello World
Procedure Parameters A Procedure, like a C or C++ Procedure(function) can take up input parameters and produce return values. Output Parameters (Returned Values) SQL Procedure Input Parameters A Procedure with Input Parameters: Create proc hellop @info1 int= 1, @info2 int As Print @info1+@info2 Calling a Procedure with parameters: Exec proc hellop 3,2
Procedure Parameters Calling a Procedure with parameters: Exec proc hellop 3,2 Here, the value ‘3’ over-rides the default value. If a paramater does not have a default value defined for it, then the DBMS requires the user to pass a value for it before execution. Eg: exec proc hellop 1: will return an error as the second parameter is not assigned any value.
Procedure Parameters Output Parameters: A Procedure can have output parameters also. The Output parameters are specified by the keyword output. Consider a procedure to add two numbers: Create proc adder @num1 int =0, @num2 int =0, As Declare @num3 int= @num1 + @num2; Print @num3; Go Executing the procedure: exec proc adder 3,4  Output: 7 A Procedure can also return a value as: return <value> NOTE The Data members in SQL (@num1) resemble the variables in c/c++. But there is a big difference: They can’t be altered directly. Eg: @num1 = @num1 +1  Is invalid. The values are assigned at the time of their declaration only.
Procedure Parameters Using the Output parameters: CREATE PROC Sales   @CustomerIDint,   @AccNumvarchar(10) OUTPUT AS SELECT @AccNum = AccNum  FROM Sales.Customer  WHERE CustomerID = @CustomerID; GO Calling a procedure with return values:  DECLARE @AccNumvarchar(10); EXEC GetCustomerAccountNumber, @AccNum OUTPUT; PRINT @AccNum;
Deleting procedures The SQL statement to drop/delete a procedure is: Drop proc <procedureName> Example: Drop proc addNumbers; Go;
Functions What is a Function? A Function is a set of sql statements which aim to accomplish the same task. How is a function different from a procedure? ,[object Object]
  It is easy to modify
  It is easy to handle return values than in procedures. In procedures, a temporary table might be necessary to carry a return value and join it with an existing table. This becomes unnecessary if functions are used instead.,[object Object]
 Control-of-flow language
 Local variables
 Various support functions for string processing, date processing, mathematics, etc.Dot Net Common Language Runtime(CLR): It is a run-time environment which runs code and provides services that make development process much easier.
Functions are better The Advantages of using functions in SQL Server 2008:
Functions The SQL Syntax for creating a function resembles that of a procedure: Create function <functionName> (argumentList)   Returns <returnValueType>   As 	Begin 	…statements… 	Return <returnValue>   End Go Let us look into some examples.

More Related Content

What's hot

VB Function and procedure
VB Function and procedureVB Function and procedure
VB Function and procedure
pragya ratan
 

What's hot (20)

Sql storeprocedure
Sql storeprocedureSql storeprocedure
Sql storeprocedure
 
Oracle: Procedures
Oracle: ProceduresOracle: Procedures
Oracle: Procedures
 
Procedures and triggers in SQL
Procedures and triggers in SQLProcedures and triggers in SQL
Procedures and triggers in SQL
 
Stored procedure
Stored procedureStored procedure
Stored procedure
 
Stored procedure in sql server
Stored procedure in sql serverStored procedure in sql server
Stored procedure in sql server
 
React js t4 - components
React js   t4 - componentsReact js   t4 - components
React js t4 - components
 
Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3 Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3
 
React + Redux. Best practices
React + Redux.  Best practicesReact + Redux.  Best practices
React + Redux. Best practices
 
Quick start with React | DreamLab Academy #2
Quick start with React | DreamLab Academy #2Quick start with React | DreamLab Academy #2
Quick start with React | DreamLab Academy #2
 
Chapter09
Chapter09Chapter09
Chapter09
 
React js t3 - es6
React js   t3 - es6React js   t3 - es6
React js t3 - es6
 
4\9 SSIS 2008R2_Training - Expression and Variables
4\9 SSIS 2008R2_Training - Expression and Variables4\9 SSIS 2008R2_Training - Expression and Variables
4\9 SSIS 2008R2_Training - Expression and Variables
 
Intro to tsql
Intro to tsqlIntro to tsql
Intro to tsql
 
PL/SQL TRIGGERS
PL/SQL TRIGGERSPL/SQL TRIGGERS
PL/SQL TRIGGERS
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
React js t5 - state
React js   t5 - stateReact js   t5 - state
React js t5 - state
 
React js t6 -lifecycle
React js   t6 -lifecycleReact js   t6 -lifecycle
React js t6 -lifecycle
 
Cleveland Meetup July 15,2021 - Advanced Batch Processing Concepts
Cleveland Meetup July 15,2021 - Advanced Batch Processing ConceptsCleveland Meetup July 15,2021 - Advanced Batch Processing Concepts
Cleveland Meetup July 15,2021 - Advanced Batch Processing Concepts
 
VB Function and procedure
VB Function and procedureVB Function and procedure
VB Function and procedure
 
3.1\9 SSIS 2008R2_Training - ControlFlow asks
3.1\9 SSIS 2008R2_Training - ControlFlow asks3.1\9 SSIS 2008R2_Training - ControlFlow asks
3.1\9 SSIS 2008R2_Training - ControlFlow asks
 

Similar to MS SQLSERVER:Sql Functions And Procedures

Unit 3(rdbms)
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)
Jay Patel
 
Unit 3(rdbms)
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)
Jay Patel
 
SQL Server 2000 Research Series - Transact SQL
SQL Server 2000 Research Series - Transact SQLSQL Server 2000 Research Series - Transact SQL
SQL Server 2000 Research Series - Transact SQL
Jerry Yang
 
Module04
Module04Module04
Module04
Sridhar P
 
New features of sql server 2005
New features of sql server 2005New features of sql server 2005
New features of sql server 2005
Govind Raj
 
Intro to tsql unit 14
Intro to tsql   unit 14Intro to tsql   unit 14
Intro to tsql unit 14
Syed Asrarali
 
PLSQLmy Updated (1).pptx
PLSQLmy Updated (1).pptxPLSQLmy Updated (1).pptx
PLSQLmy Updated (1).pptx
vamsiyadav39
 
Introduction to Threading in .Net
Introduction to Threading in .NetIntroduction to Threading in .Net
Introduction to Threading in .Net
webhostingguy
 
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu   (obscure) tools of the trade for tuning oracle sq lsTony Jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
InSync Conference
 
Msql
Msql Msql
Msql
ksujitha
 

Similar to MS SQLSERVER:Sql Functions And Procedures (20)

Unit 3(rdbms)
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)
 
Unit 3(rdbms)
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)
 
Unit 3
Unit 3Unit 3
Unit 3
 
Watch Re-runs on your SQL Server with RML Utilities
Watch Re-runs on your SQL Server with RML UtilitiesWatch Re-runs on your SQL Server with RML Utilities
Watch Re-runs on your SQL Server with RML Utilities
 
SQL Server 2000 Research Series - Transact SQL
SQL Server 2000 Research Series - Transact SQLSQL Server 2000 Research Series - Transact SQL
SQL Server 2000 Research Series - Transact SQL
 
Module04
Module04Module04
Module04
 
Evolutionary db development
Evolutionary db development Evolutionary db development
Evolutionary db development
 
New features of sql server 2005
New features of sql server 2005New features of sql server 2005
New features of sql server 2005
 
Intro to tsql unit 14
Intro to tsql   unit 14Intro to tsql   unit 14
Intro to tsql unit 14
 
Data Access with JDBC
Data Access with JDBCData Access with JDBC
Data Access with JDBC
 
Procedure n functions
Procedure n functionsProcedure n functions
Procedure n functions
 
SQl
SQlSQl
SQl
 
PLSQLmy Updated (1).pptx
PLSQLmy Updated (1).pptxPLSQLmy Updated (1).pptx
PLSQLmy Updated (1).pptx
 
Introduction to Threading in .Net
Introduction to Threading in .NetIntroduction to Threading in .Net
Introduction to Threading in .Net
 
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu   (obscure) tools of the trade for tuning oracle sq lsTony Jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
 
Msql
Msql Msql
Msql
 
Oracle: Procedures
Oracle: ProceduresOracle: Procedures
Oracle: Procedures
 
1
11
1
 
embedded-static-&dynamic
embedded-static-&dynamicembedded-static-&dynamic
embedded-static-&dynamic
 
Client sidescripting javascript
Client sidescripting javascriptClient sidescripting javascript
Client sidescripting javascript
 

More from sqlserver content

MS SQL SERVER: Microsoft naive bayes algorithm
MS SQL SERVER: Microsoft naive bayes algorithmMS SQL SERVER: Microsoft naive bayes algorithm
MS SQL SERVER: Microsoft naive bayes algorithm
sqlserver content
 

More from sqlserver content (20)

MS SQL SERVER: Using the data mining tools
MS SQL SERVER: Using the data mining toolsMS SQL SERVER: Using the data mining tools
MS SQL SERVER: Using the data mining tools
 
MS SQL SERVER: SSIS and data mining
MS SQL SERVER: SSIS and data miningMS SQL SERVER: SSIS and data mining
MS SQL SERVER: SSIS and data mining
 
MS SQL SERVER: Programming sql server data mining
MS SQL SERVER:  Programming sql server data miningMS SQL SERVER:  Programming sql server data mining
MS SQL SERVER: Programming sql server data mining
 
MS SQL SERVER: Olap cubes and data mining
MS SQL SERVER:  Olap cubes and data miningMS SQL SERVER:  Olap cubes and data mining
MS SQL SERVER: Olap cubes and data mining
 
MS SQL SERVER: Microsoft time series algorithm
MS SQL SERVER: Microsoft time series algorithmMS SQL SERVER: Microsoft time series algorithm
MS SQL SERVER: Microsoft time series algorithm
 
MS SQL SERVER: Microsoft sequence clustering and association rules
MS SQL SERVER: Microsoft sequence clustering and association rulesMS SQL SERVER: Microsoft sequence clustering and association rules
MS SQL SERVER: Microsoft sequence clustering and association rules
 
MS SQL SERVER: Neural network and logistic regression
MS SQL SERVER: Neural network and logistic regressionMS SQL SERVER: Neural network and logistic regression
MS SQL SERVER: Neural network and logistic regression
 
MS SQL SERVER: Microsoft naive bayes algorithm
MS SQL SERVER: Microsoft naive bayes algorithmMS SQL SERVER: Microsoft naive bayes algorithm
MS SQL SERVER: Microsoft naive bayes algorithm
 
MS SQL SERVER: Decision trees algorithm
MS SQL SERVER: Decision trees algorithmMS SQL SERVER: Decision trees algorithm
MS SQL SERVER: Decision trees algorithm
 
MS SQL Server: Data mining concepts and dmx
MS SQL Server: Data mining concepts and dmxMS SQL Server: Data mining concepts and dmx
MS SQL Server: Data mining concepts and dmx
 
MS Sql Server: Reporting models
MS Sql Server: Reporting modelsMS Sql Server: Reporting models
MS Sql Server: Reporting models
 
MS Sql Server: Reporting manipulating data
MS Sql Server: Reporting manipulating dataMS Sql Server: Reporting manipulating data
MS Sql Server: Reporting manipulating data
 
MS Sql Server: Reporting introduction
MS Sql Server: Reporting introductionMS Sql Server: Reporting introduction
MS Sql Server: Reporting introduction
 
MS Sql Server: Reporting basics
MS Sql  Server: Reporting basicsMS Sql  Server: Reporting basics
MS Sql Server: Reporting basics
 
MS Sql Server: Datamining Introduction
MS Sql Server: Datamining IntroductionMS Sql Server: Datamining Introduction
MS Sql Server: Datamining Introduction
 
MS Sql Server: Business Intelligence
MS Sql Server: Business IntelligenceMS Sql Server: Business Intelligence
MS Sql Server: Business Intelligence
 
MS SQLSERVER:Feeding Data Into Database
MS SQLSERVER:Feeding Data Into DatabaseMS SQLSERVER:Feeding Data Into Database
MS SQLSERVER:Feeding Data Into Database
 
MS SQLSERVER:Doing Calculations With Functions
MS SQLSERVER:Doing Calculations With FunctionsMS SQLSERVER:Doing Calculations With Functions
MS SQLSERVER:Doing Calculations With Functions
 
MS SQLSERVER:Deleting A Database
MS SQLSERVER:Deleting A DatabaseMS SQLSERVER:Deleting A Database
MS SQLSERVER:Deleting A Database
 
MS SQLSERVER:Customizing Your D Base Design
MS SQLSERVER:Customizing Your D Base DesignMS SQLSERVER:Customizing Your D Base Design
MS SQLSERVER:Customizing Your D Base Design
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 

MS SQLSERVER:Sql Functions And Procedures

  • 1. 12 SQL SERVER: SQLFUNCTIONS AND PROCEDURES
  • 2. SQL Procedures What is an SQL Procedure? An SQL Procedure contains a group of sql statements which solve a common purpose. Syntax: Consider a simple SQL Procedure: Create proc printProcedure As Print ‘Hello World’ go Create proc <procedureName> As …. Statements… Print is a command in SQL Server 2008. It is used to print a string on the screen. NOTE: The SQL Procedures that we learn here are stored in the system by the DBMS. They are hence known as stored procedures
  • 3. Altering stored procedures How to alter a SQL stored procedure? A Stored procedure can be altered using the alter proc command. Syntax: Consider a simple SQL Procedure: Alter proc printProcedure As Print ‘New Hello World’ go Alter proc<procedureName> As …. New Statements…
  • 4. Executing Procedures The Main advantage of using a stored procedure is its reusability, i.e., a procedure can be called any time that it needs to be executed. An SQL procedure can be executed using the exec command: Exec <ProcedureName> Example: Create proc printProcedure As Print ‘New Hello World’ Go Exec printProcedure OUTPUT: New Hello World
  • 5. Procedure Parameters A Procedure, like a C or C++ Procedure(function) can take up input parameters and produce return values. Output Parameters (Returned Values) SQL Procedure Input Parameters A Procedure with Input Parameters: Create proc hellop @info1 int= 1, @info2 int As Print @info1+@info2 Calling a Procedure with parameters: Exec proc hellop 3,2
  • 6. Procedure Parameters Calling a Procedure with parameters: Exec proc hellop 3,2 Here, the value ‘3’ over-rides the default value. If a paramater does not have a default value defined for it, then the DBMS requires the user to pass a value for it before execution. Eg: exec proc hellop 1: will return an error as the second parameter is not assigned any value.
  • 7. Procedure Parameters Output Parameters: A Procedure can have output parameters also. The Output parameters are specified by the keyword output. Consider a procedure to add two numbers: Create proc adder @num1 int =0, @num2 int =0, As Declare @num3 int= @num1 + @num2; Print @num3; Go Executing the procedure: exec proc adder 3,4 Output: 7 A Procedure can also return a value as: return <value> NOTE The Data members in SQL (@num1) resemble the variables in c/c++. But there is a big difference: They can’t be altered directly. Eg: @num1 = @num1 +1 Is invalid. The values are assigned at the time of their declaration only.
  • 8. Procedure Parameters Using the Output parameters: CREATE PROC Sales @CustomerIDint, @AccNumvarchar(10) OUTPUT AS SELECT @AccNum = AccNum FROM Sales.Customer WHERE CustomerID = @CustomerID; GO Calling a procedure with return values: DECLARE @AccNumvarchar(10); EXEC GetCustomerAccountNumber, @AccNum OUTPUT; PRINT @AccNum;
  • 9. Deleting procedures The SQL statement to drop/delete a procedure is: Drop proc <procedureName> Example: Drop proc addNumbers; Go;
  • 10.
  • 11. It is easy to modify
  • 12.
  • 15. Various support functions for string processing, date processing, mathematics, etc.Dot Net Common Language Runtime(CLR): It is a run-time environment which runs code and provides services that make development process much easier.
  • 16. Functions are better The Advantages of using functions in SQL Server 2008:
  • 17. Functions The SQL Syntax for creating a function resembles that of a procedure: Create function <functionName> (argumentList) Returns <returnValueType> As Begin …statements… Return <returnValue> End Go Let us look into some examples.
  • 18. Functions A Sample function: Consider a function that takes two numbers and finds their sum: Create function adder (@num1 int,@num2 int) Returns int As Begin Declare @num3 int; Set @num3 = @num1+@num2; Return @num3; End go Note that the SET keyword is used to change the value of a variable Calling the function: The Prefix dbo instructs the DBMS that you are the database owner Print dbo.adder(2,4) go
  • 19. Deleting Functions The SQL statement to drop/delete a function is similar to that of a procedure: Drop function <procedureName> Example: Drop function addNumbers; Go;
  • 20.
  • 21. Creating Procedures
  • 22. Modifying existing procedures
  • 23. Deleting procedures
  • 25. Creating functions
  • 26. Modifying existing functions
  • 27.