6. TRY… CATCH…Alien?
• Your Code in the TRY block
• Check for the Errors in the CATCH block
Can be found in
Modern Programming Languages
7. TRY… CATCH…T-SQLStyle
• Your SQLStatement in the TRY block
• Check for the Errors in the CATCH block
Find it in
Transact-SQL
sql_statement:
any Transact-SQL statement
statement_block :
any group of Transact-SQL statements
in a batch or enclosed in a BEGIN…END block.
8. Why your codeFAILED?
List of SQL Server functions to identify:
ERROR_NUMBER() returns the number of the error
ERROR_SEVERITY() returns the severity of the error
ERROR_STATE() returns the error state number
ERROR_PROCEDURE() returns the name of the stored procedure or trigger where the error
occurred, this will be NULL if you run an ad-hoc SQL statement
ERROR_LINE() returns the line number inside the routine that caused the error
ERROR_MESSAGE() returns the complete text of the error message.
The text includes the values supplied for any substitutable parameters, such as
lengths, object names, or times
9. NEED to see some T-SQL
Nice Result
Check out what
being selected
out?
10. What can we do with this ?
I will Hold Error
Info
I will Fill the
Error Info
12. Information isWealth!
the ability to log all errors plus any
other information you want to capture like
user name, host name etc with 1 Stored
Proc that you can call from everywhere
the ability to do anything with the
logged data Once YOU have it.
I CAN NOT do ANYTHING on SOMETHING until I have that THING!
17. The Feature
• The DataCompression featureof SQL Server, can reduce
thestorage footprint of your databases.
– Often, datacompression mayleadto degrade inCPU
performance duetocompress/decompress;
• However,SQLServer2008datacompressionsimply storesdatamore
efficiently intherowsandpages,which meansthatthein-memory
storageandIOOperations datamanagementisefficient.
18. Mainly 2 Types ofCompression
• SQLServer 2008supports2specifictypesofdata compressionmethods:
– Row Compression
• lower level whichstoresthe fixed characterstrings by using variable-lengthformat bynot
storingthe blankcharacters.NULLand 0 values acrossalldatatypes areoptimized and take
no bytes.
– Page Compression
• Is Higherlevel compressing & uses twotypes of compression
– Prefix-Prefixcompressionworkson common values patternacross all rowson thepage
– Dictionary - Workson exactvaluesmatchpatternacrossallpages.
19. Considerations
• Datacompressvery well:
– Columnswith numericor fixed-length characterdata types wheremost valuesdon’t requireall the
allocated bytes: For example, integers wheremost values are less than1000
– Null-ablecolumns wherea significant numberof the rows havea NULLvalue for the column
– Significant amounts of repeating data values orrepeating prefixvalues in the data
• Somepatternsof datathatdonotbenefitmuch fromcompressionare:
– Columnswith numericor fixed-length characterdata typeswheremost values requireall the bytes
allocated for the specific data type
– Not muchrepeating data
– Repeating data with non-repeatingprefixes
– Data stored out of the row
– FILESTREAMdata
• Compression is Version dependant [Cannot be decompressed on another version]
20. ImplementData compression
• You can implement both types of data compression when
you create a table or index, or by altering existing tables
and indexes. You can do this by using Transact-SQL code
or theDataCompression Wizard.
21. USE [AdventureWorks]
Go
/*Estimating how much space can be saved by row or page*/
EXEC
sp_estimate_data_compression_savings 'Sales', 'SalesOrderDetail', NULL, NULL,'ROW' ;
Go
EXEC
sp_estimate_data_compression_savings 'Sales', 'SalesOrderDetail', NULL,NULL, 'PAGE' ;
GO
---------------------------------------------------------------------------------------------------------------
/*Enabling Table compression by row or page */
ALTER TABLE Sales.SalesOrderDetail
REBUILD WITH (DATA_COMPRESSION = ROW);
–OR
ALTER TABLE [Sales].[SalesOrderDetail] REBUILD PARTITION = ALL
WITH (DATA_COMPRESSION = PAGE)