welcome to beginners tutorial Microsoft sql server part 6 today we are going
to learn about sql server function what is a function how to create it how
to execute functions please subscribe to my channel more exciting videos are
coming every week function is a database object in sql server basically it is a
set of sql statement that accepts only the input parameters perform actions
and return result function can only return single value or a table it is
like view but view does not accept parameter it also look like stored
procedure but a stored procedure cannot be used in relation so summary is
function act like a stored procedure it can also be used as a table in
relationship let's do some practical first run sql server management studio
and log into it in the object explorer window select database then test_db we
have already created in our earlier tutorial expand it go to programmability
then function these are main types of functions in this tutorial we'll learn
how to create a table value function is the template before making any function
you have to plan first what to do with the function let's explain our plan you know
we have already created a table for customer
in this table we have some demo data customer name countries and phone
numbers we need to filter customers as per their country we can manually edit
this template or use this wizard author name you can put creation date
description also so that you can understand what is the purpose of this
function function name is mandatory filter country parameter will be country
can give any name data type will be same as field datatype we need only
one parameter so I am deleting unnecessary text we can type sql
statement here or use design query editor so the customer add close
select fields in the filter section type the declared parameter select ok the wizard
automatically created sql statement execute it error due to wrong parameter
parameter must be same as it have declared here is the function we have
just created execution of a function is little bit different than stored procedure
script function as select to new query editor it generates a sql
statement in this bracket type parameter value in single quotation parameter
value will be usa
here you can see our function successfully filtered customers from USA
I think you have understand what is functions please subscribe to my channel
more exciting videos are coming every week