SQL Server Sequences

In SQL Server, you can create an autonumber field by using sequences. A sequence is an object in SQL Server (Transact-SQL) that is used to generate a number sequence. This can be useful when you need to create a unique number to act as a primary key. Creating sequences. Using sequences. Drop Sequences Properties of... » read more

User Defined Table Types in SQL

So what actually are User defined table types in SQL server? The easiest way to appreciate their value is to think of them as a strongly typed temporary table definition that has the added ability to be passed to a stored procedure as a parameter. Once used in a procedure or function can’t be altered... » read more

Moving TempDB To Another Drive

Because tempdb is re-created each time the instance of SQL Server is started, you do not have to physically move the data and log files. Remember to restart SQL Server after you run the move script for the changes to go into effect. Determine the logical file names of the tempdb database and their current... » read more

Run SQL from Batch File using SQLCMD

The sqlcmd utility lets you enter Transact-SQL statements, system procedures, and script files through a variety of available modes: At the command prompt. In Query Editor in SQLCMD mode. In a Windows script file. In an operating system (Cmd.exe) job step of a SQL Server Agent job. The utility uses ODBC to execute Transact-SQL batches. Run sql from command... » read more

Using Temp Table

By using SELECT … INTO, you don’t have to define the columns of the temporary table. The temporary table columns will be based on the SELECT columns.

Create Database Backup using Maintenance Plans

Database Server -> Management -> Maintenance Plans -> Maintenance Plan Wizard After the Maintenance Plan has been created… You can edit the maintenance plan using SSMS. A database job will be created for each plan. Note: If you want to remove the backup files after a certain days, make sure you also select the Maintenance... » read more

Linked Server Login Timeout

Error: Linked server timeout after 10 seconds. TCP Provider: Timeout error [258]. [SQLSTATE 42000] (Error 258)  OLE DB provider “SQLNCLI11” for linked server “xxxxxx” returned message “Login timeout expired”. [SQLSTATE 01000] (Error 7412)  OLE DB provider “SQLNCLI11” for linked server “xxxxxx” returned message “Unable to complete login process due to delay in login response”. [SQLSTATE... » read more

AUTO_UPDATE_STATISTICS

The default option is ON. How do the statistics increase the performance of your SQL Server query execution? The statistical histograms are used by the Query Optimizer to choose the optimal query execution plan. If a query predicate contains a column with statistics, the Query Optimizer does not have to estimate the number of rows... » read more