Author

@@ServerName

Get the actual server name of the current SQL Server. Useful when you are using listeners to connect into SQL Server and need to know the exact server name you are connected into.

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

Windows Batch Script Example

In Windows, the batch file is a file that stores commands in a serial order. Command line interpreter takes the file as an input and executes in the same order. A batch file is simply a text file saved with the .bat or .cmd file extension. It can be written using Notepad or any other... » 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