Using SQL Server 2012 FileTables

Basit's SQL Server Tips

SQL Server 2012 allows you to store file/directories in a special table called FileTable that builds on top of SQL Server FILESTREAM technology. As per Microsoft BOL, “FileTable lets an application integrate its storage and data management components, and provides integrated SQL Server services – including full-text search and semantic search – over unstructured data and metadata.”

FileTable has a fixed schema and each row of this table represents a file or a directory. The main advantage of FileTable is that it supports Win32APIs for file or directory management which mean we can access file and directory hierarchy through a Windows Share and database storage is transparent to Win32 application. Files can be bulk loaded, updated as well as managed in T-SQL like any other column. SQL Server also supports backup and restore job for this feature.

In this tip we will take a look at how to use FileTable…

View original post 628 more words

Transact-SQL analytic functions in SQL Server can help solve problems quickly

Like other mainstream commercial database systems, SQL Server supports analytic functions in Transact-SQL to depict complex analytical tasks. With the help of these analytic functions, we can perform common analyses, such as ranking, percentiles, moving averages and cumulative sums that can be expressed concisely in a single SQL statement.

The first batch of Transact-SQL analytic functions came with the release of SQL Server 2005, which included a variety of ranking functions, such as ROW_NUMBER, RANK, DENSE_RANK and NTILE. SQL Server 2012 introduced eight more Transact-SQL analytic functions: PERCENT_RANK, CUME_DIST, PERCENTILE_CONT, PERCENTILE_DISC, LEAD, LAG, FIRST_VALUE and LAST_VALUE.

Checkout my article here, in which I explained and demonstrated the use of Transact-SQL analytic functions. With the help of these analytic functions, we can quickly solve complex analytical tasks and also eliminate the use of programming self-joins, correlated subqueries and/or use fewer temporary tables compared to the counterparts without such functions.

This article is published on SearchSQLServer.techtarget.com.

Database Recovery Advisor feature of SQL Server 2012

SQL Server 2012 introduces Database Recovery Advisor that provides significant user experience improvements to the ways DBAs can restore databases with SQL Server Management Studio. As we know, SQL Server provides a variety of backup types, so creating the proper recovery sequence for each point in time can be tricky at times. This is where Database Recovery Advisor is useful, because it makes the database restoration process more agile by helping the customers to create more predictable and optimal recovery sequence.

The Database Recovery Advisor provides a visual timeline from the backup history of the database and then presents the available points in time at which the user can restore the database, algorithms to streamline the identification of the appropriate sets of backup media to restore the database back to a specific point in time. By default, the Database Recovery Advisor tries to restore the database from the last backup taken, but as I said earlier, we can use visual timeline feature to restore the database to an earlier point than last full backup.

The Database Recovery Advisor is available via Restore Database dialog box, which you can launch as follow:

1) Right-click database which you want to restore and then navigate to “Databases…” and then click on “Databases…” to launch Restore Database dialog box.

2) In Restore Database dialog box, click “TimeLine…” button to launch Database Recovery Advisor visual timeline.

3) Choose “Specific date and time” option and then use the arrow to specify the restore point. After choosing the appropriate restore restore point, click OK button to return to Database Restore dialog box (see below):

4) Click OK button in Database Restore dialog box to start the database restore (see below):

Conclusion

The Database Recovery Advisor is a great feature of SQL Server 2012, allowing users with a visual timeline of database restore points from backup history. As we have seen in this post, this feature is easy to use and with the help of this feature we can easily perform point-in-time database restore.

Recovering from out-of-disk space conditions for tempdb

Another potential problem that you need to tackle as a DBA is running out of disk space on the hard disk that contains tempdb.This is because SQL Server makes extensive use of tempdb when:

  • Tracking versions for row-versioning concurrency.
  • Performing bulk load operations on tables with triggers enabled.
  • Running DBCC CHECKDB.
  • Rebuilding an index with SORT_IN_TEMPDB option.
  • Variables of LOB data types.
  • Storing intermediate query results, for example, during joins, aggregates, or sorts.
  • Service broker dialog information.
  • Caching temporary objects and tables.
  • Storing inserted and deleted tables in triggers.
  • Running sp_xml_preparedocument.

Continue reading

Performing Unattended Installs of SQL Server 2012

In my post here, I’ve discussed the procedure to perform attended installation of SQL Server 2012 on a Windows Server 2008.

Now imagine, you have multiple SQL Server 2012 instances to install with the same configuration on the multiple servers and you want this task to be done as quickly and consistently as possible. When this is the case, you may choose the unattended installation option. SQL Server unattended installation option lets administrators install SQL Server on multiple machines with little or no user interactions. SQL Server 2012 unattended installations can be done using command line parameters or configuration files. All SQL Server step-up screen entries and the dialog responses are made automatically by using information stored in the configuration file or by command-line parameters.

This article shows you the steps to perform unattended installation of SQL Server 2012 on a Windows Server 2008 system by using command line and configuration file.

Continue reading

How to move master and resource system databases?

I received an phone call from a friend today asking how to move master and resource system databases in Microsoft SQL Server 2012.

Well, the process is very simple and is explained in this blog post:

Moving “master” database

The following are the steps to move master database:

  1. Launch SQL Server Configuration Manager and display the Properties for the SQL Server service.

  2. Activate Startup Parameters and modify the datafile (-d) and log file (-l) startup parameters to reference the new location (see below):

  3. Click Apply and then stop the SQL Server service (see below):

  4. Move the master database files to the new location and then start the SQL Server service (see below):

Moving “resource” database (only applies to SQL Server 2005)

The following are the steps to move “resource” database:

  1. Start in master-only recovery mode by running:

    NET START MSSQLSERVER /f /T3608

  2. Launch a command prompt and run sqlcmd.

  3. Use the ALTER DATABASE statement with the MODIFY FILE option to specify the new location for the resource database data and log files.

  4. Use the ALTER DATABASE statement to make the Resource database read-only.

  5. Stop the SQL Server service.

  6. Move the database files for the “resource” database to new location.

  7. Start the SQL Server service.

I hope you will find this information useful 😀

Retrieving password policy settings for SQL login accounts

Today, I wrote the following query for our internal audit report for SAS70. This query provides all the necessary details about SQL Logins policy settings.

This query is using LOGINPROPERTY function to retrieve the sql login policy settings information:

USE [master]
GO

DECLARE @PwdExpirationAge [int]

SET @PwdExpirationAge = 28

SELECT [name] AS [SQL_User]
	,LOGINPROPERTY([name], 'PasswordLastSetTime') AS [PasswordLastResetDT]
	,@PwdExpirationAge - DATEDIFF(DAY, CONVERT([datetime], LOGINPROPERTY([name], 'PasswordLastSetTime')), GETDATE()) AS [DaysUntilExpiration]
	,LOGINPROPERTY([name], 'BadPasswordCount') AS [BadPasswordCount]
	,LOGINPROPERTY([name], 'BadPasswordTime') AS [BadPasswordDT]
	,LOGINPROPERTY([name], 'HistoryLength') AS [HistoryLength]
	,LOGINPROPERTY([name], 'IsExpired') AS [IsExpired]
	,LOGINPROPERTY([name], 'IsLocked') AS [IsLocked]
	,LOGINPROPERTY([name], 'IsMustChange') AS [IsMustChange]
	,LOGINPROPERTY([name], 'LockoutTime') AS [LockoutTime]
FROM [sys].[sql_logins]
GROUP BY [name];
GO

I hope you will find this query useful.