View
24
Download
2
Embed Size (px)
DESCRIPTION
then for you...
Citation preview
UDF &VIEWSIN SQL
Muhammed Tanveer [email protected] Thanveer Danish MelayiMuhammed Thanveer. MLinkedin Profile
TYPING SPEED:25
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
UDFThere 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
Scalar User-Defined FunctionA 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.
exampleCREATE FUNCTION AddTwoNumbers(@a int,@b int)RETURNS intASBEGINRETURN @a + @bENDSELECT dbo.AddTwoNumbers(30,20)
Table-valued functionsA 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
example CREATE FUNCTION GetAllProducts( )RETURNS TABLEASRETURN(SELECT ProductID, ProductName, RetailPrice, CategoryFROM CurrentProducts)GO
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
syntaxCREATE VIEW view_name AS SELECT column_name(s) FROM table_name WHERE condition
example CREATE VIEW [Current Product List] ASSELECT ProductID,ProductNameFROM ProductsWHERE Discontinued=No
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
thank you
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.
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
Emarald Mall (Big Bazar Building)Mavoor Road, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550
NC Complex, Near Bus StandMukkam, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550
Cafit Square,Hilite Business Park,Near Pantheerankavu,Kozhikode
Start up VillageEranakulam,Kerala, India.Email: [email protected]
Contact Us