Wednesday, February 27, 2013

Technical tips for SQL Server

As you were probably aware, last Friday we had techweets which was an initiative by South Asia MVPs to post day long technical tweets. In case you missed it, I'm sharing the tips through this blog which I'd tweeted as a part of this.


  1. SQLServer supported float notations are Scientific and Alt. scientific as per ex: SELECT '2d5' + 2e6 + 1e-5.  

  1. Lookup() function can be used in SSRS 2008 R2 to merge two dataset fields
    within the same tablix.  

  1. fn_dblog() function can be used to retrieve deleted data from active portion of tran log if its not cleared

  1. sys.dm_os_windows_info DMV can be used in SQL 2012 to get os locale settings of the server.  

  1. sys.dm_server_services DMV can be used from SQL 2008 R2 to get running status of SQL Server services.  

  1. Composable DML enables DML data exposed through OUTPUT clause to be used as a source for INSERT query

  1. cross server cross db object dependencies can be viewed using sys.sql_expression_dependencies in SQL 2008.  

  1. SQL Data Sync can be used for automated periodic data sync up between Win Azure SQL and on premise SQL DB

  1. Filtered indexes have has_filter column value as 1 in sys.indexes view.  

  1. Filetable last_access_time value remains unchanged until disablelastaccess setting of os is reset by fsutil.  

  1. Runtime debugging of SSIS package data flow paths can be done by adding datataps in SSIS 2012.  

  1. Pagination can be easily implemented in SELECT queries using ORDER BY..OFFSET construct in SQL 2012

  1. sp_foreignkeys gives the details of foreignkeys referring the linked server table's primary key.  

  1. Quarter value for a date can be obtained using formula QUOTIENT((MONTH([DateField])-1),3)+1 in DAX.  

  1. The SQL agent jobs dependent on an object can be identified using command field in msdb sysjobsteps table.  

  1. SSIS 2012 supports ODBC connection managers which can used to connect to SQL Azure instances.  

  1. Date and time values passed to SQL Server are interpreted as per language settings of the server.  

  1. REPLACE function preserves trailing spaces in SQL 2008 as against trimming performed in SQL 2005.  

  1. CDC is implemented in SSIS 2012 using CDC Control flow task and CDC Source and Splitter tasks in data flow  

  1. local-name() Xquery function can be used to return node/attribute names within a XML document in T-SQL.

  1. PARSE() function in SQL 2012 parses and converts string values to any datatype in specified culture format.

  1. Table Value Constructor can be used with FOR XML PATH to generate adhoc XML from set of variable values.

  1. Shared cache connection managers enable reuse of cache among packages in SSIS 2012 project deployment model.  

  1. DQS cleansing task is available in SSIS 2012 for source data cleansing against a DQS Knowledge base.  

  1. HalfYear value for a date can be obtained using formula QUOTIENT((MONTH([ShipDate])-1),6)+1 in DAX.  

  1. Expression task is available for variable value manipulations in SSIS 2012 data flow task.  

  1. Java.util functions can be used inside SSIS script task for zipping and unzipping of files  

  1. Selective XML Indexes enables you to index selected xpath contents within a XML document in SQL 2012.  

  1. THROW is preferred over RAISERROR for raising exceptions in SQL 2012. 
        1. For easy insertion/modification of sparse columns add a columnset column in table including all of them.

  1. sql:column() function can be used to pass table column values inside XML Xpath queries.  

  1. TOKEN function in SSIS 2012 can be used for parsing a delimited string and getting a substring within it.   

  1. max_worker_thread setting in msdb syssubsystems table controls the no of concurrent running sql agent jobs.   

  1. sql:variable() function can be used to pass variable values inside XML Xpath queries.  

  1. SQLNativeClient11 the default provider with SQL 2012 wont support SQL2000 linked servers.use v10 if required

  1. Attributes within XML node can be retrieved by using NodeName/@* argument within Xpath query.   

  1. Running value calculations can be done inline in SQL 2012 using UNBOUNDED PRECEDING option in PARTITION BY.   

  1. ORDER BY used inside view from SQL 2005 will not guarantee ordered data retrieval from it.   

  1. SSRS 2012 reports can be rendered as images using URL parameters rs:Format=IMAGE&rc:OutputFormat=JPEG/BMP/..   

  1. Fast load option can be used in OLEDB destinations in SSIS for faster data transfer.  

  1. SQL Data Sync can be used for automated periodic data sync up between Win Azure SQL and on premise SQL DB

  1. Filter option in object explorer can be used for quick pattern search for object names and script them out.

  1. HOST_NAME () returns name of workstation which runs the t-sql statement.  

  1. ISNUMERIC returns 1 for any expression which is valid numeric type ex:$,+,- etc.  

  1. Table valued parameters can be passed only in READONLY mode in SQL routines.  

  1. The metadata of resultset can be specified using WITH RESULT SETS option in EXECUTE statement SQL 2012.

  1. EVENTDATA function can be used to return details on the event inside a DDL or logon trigger..  

  1. Style value of 126,127 can be used for parsing XML based date format values to datetime in CONVERT()

  1. To select a value among enumerated list by passing an index, use CHOOSE function in SQL 2012  

  1. Table Value Constructor can be used with FOR XML PATH to generate adhoc XML from set of variable values.
If you need any more detail/ clarification on any of above technical tip, feel free to comment and I'll reply with requested information.
We're planning more initiatives like this in future too so make sure you follow me on twitter (@visakh16) to get the updates.