Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Udf&views in sql...by thanveer melayi
1.
2. UDF &VIEWS
IN SQL
Muhammed Tanveer Melayi
shernoobi@gmail.com
Muhammed Thanveer Danish Melayi
Muhammed Thanveer. M
Linkedin Profile
TYPING SPEED:25
3. Disclaimer: This presentation is prepared by trainees of
baabtra.com as a part of mentoring program. This is not
official document of baabtra.com – Mentoring Partner
4. UDF
There are three Types of UDFS in Sql Server:
1. Scalar
2. Inline Table-Valued
3. Multi-statement Table-Valued
• It can be used with SQL select queries same like we use any other scalar or
aggregate functions that we discussed earlier(eg :sum(),Avg()ect)
• UDF must return value
5. Scalar User-Defined Function
A Scalar UDF can accept 0 to many input parameter and will return a
single value. A Scalar user-defined function returns one of the scalar
(int, char, varchar etc) data types. Text, ntext, image and timestamp
data types are not supported.
example
CREATE FUNCTION AddTwoNumbers
(
@a int,
@b int
)
RETURNS int
AS
BEGIN
RETURN @a + @b
END
SELECT dbo.AddTwoNumbers(30,20)
6. Table-valued functions
A table-valued UDF is a function that accepts parameters
and returns the results in the form of a table.
This type of function is special because it returns a table
that you can query the results of and join with other
tables
7. example
CREATE FUNCTION GetAllProducts( )
RETURNS TABLE
AS
RETURN
(SELECT ProductID, ProductName, RetailPrice, Category
FROM CurrentProducts)
GO
8. VIEWS
• A view is a customized representation of data from one
or more tables.The table that the view is referencing are
known as base table
• A view can be considered as a stored query or virtual
table
• View Doesn’t take any storage space
9. syntax
CREATE VIEW view_name
AS
SELECT column_name(s)
FROM table_name
WHERE condition
example
CREATE VIEW [Current
Product List] AS
SELECT
ProductID,ProductNam
e
FROM Products
WHERE
Discontinued=No
10. Views - Advantages
• Data Security
No need to give permission on the table.infact a view can be
created,having only selected
• Simplicity
A very complicated query can be saved as a view definition.When
needed can be called by its view name
• Removes Dependency
Can be very helpful to remove the dependency from the
underlying tables.suppose a view is created join servel tables
12. Want to learn more about programming or Looking to become a good programmer?
Are you wasting time on searching so many contents online?
Do you want to learn things quickly?
Tired of spending huge amount of money to become a Software professional?
Do an online course
@ baabtra.com
We put industry standards to practice. Our structured, activity based courses are so designed
to make a quick, good software professional out of anybody who holds a passion for coding.
13. Follow us @ twitter.com/baabtra
Like us @ facebook.com/baabtra
Subscribe to us @ youtube.com/baabtra
Become a follower @ slideshare.net/BaabtraMentoringPartner
Connect to us @ in.linkedin.com/in/baabtra
Give a feedback @ massbaab.com/baabtra
Thanks in advance
www.baabtra.com | www.massbaab.com |www.baabte.com
14. Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Cafit Square,
Hilite Business Park,
Near Pantheerankavu,
Kozhikode
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com