Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
15 views

Transact SQL

T-SQL is a query language used in Microsoft SQL Server that adds procedural elements like variables, transactions, and error handling to SQL. It allows importing data with BULK INSERT and provides string and data functions. Aggregate functions operate on collections and return single values for counting, summing, averaging, finding minimums and maximums. Rank functions allocate integer ranks within groups. Scalar functions always return a single value from an input and include functions for case conversion, substring extraction, length, rounding, and formatting.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Transact SQL

T-SQL is a query language used in Microsoft SQL Server that adds procedural elements like variables, transactions, and error handling to SQL. It allows importing data with BULK INSERT and provides string and data functions. Aggregate functions operate on collections and return single values for counting, summing, averaging, finding minimums and maximums. Rank functions allocate integer ranks within groups. Scalar functions always return a single value from an input and include functions for case conversion, substring extraction, length, rounding, and formatting.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Transact SQL

What’s T-SQL?
• T-SQL is a query lsnguage specific to SQL server
• Mostly performs operations like retrieving data from a single row, insert new row and
retrieving multiple rows
• T-SQL is a procedural language used by Microsoft in SQL Server. It adds declared
variables, transaction control, error and exception handling, and row processing to SQL.
Features of T-SQL
• T-SQL has a BULK INSERT statement that allows users to import a file into the
database table or view in a user-specified format.
• T-SQL provides various support functions for string processing and data processing
Types of functions in T-SQL
• Aggregate Functions: It operates on a collection of values but returns a single value.
• Ranking Function: It returns a ranking value for each partitioning row.
• Scalar Functions: It operates on a single value and returns a single value.
Aggregate Function
• This function returns one value after calculating multiple values of a columns

There are 5 types of SQL aggregate functions:


• Count()
• Sum()
• Avg()
• Min()
• Max()
Why use Aggregate functions?
• They allow us to perform calculations on large data sets quickly and efficiently.
• These functions generate statistical reports, perform financial analysis, and manage
inventory levels.
• In some cases, using aggregate functions can lead to more efficient query execution
compared to retrieving all individual rows and performing calculations in application
code.
Examples (AVG function)
Rank function
• The RANK() function allocates a rank, that is, an integer number to each row within a
group of data sets. The RANK() function is also known as the window function
• Three questions to look at before ranking
• Rank what?
• Within what group?
• Rank by what?
Example
Scalar Function
• Scalar functions are the built-in functions in SQL, and whatever be the input provided to
the scalar functions, the output returned by these functions will always be a single value.
• commonly used scalar functions in SQL

1. UCASE()

2. LCASE()

3. MID()

4. LENGTH()

5. ROUND()

6. NOW()

7. FORMAT()
Scalar Function Description
Example

You might also like