Wednesday, 15 November 2017

How to create query shortcut in SQL server

Hi All,  

Today I am going to explain how to create query shortcut in SQL server. 

Go to tools.




Click on Options-> Keyboard -> Query Shortcuts.

In the right site you can see query shortcuts and command. Please enter your query.



Click on save button.

Open new query window (Ctrl+N) and enter your table name.

Select your table name and press Ctrl+3 shortcut. 

Thanks for reading :) 

How to restore database by using T-SQL Scripts

Hi All,  

Today I am going to explain how to restore database by using T-SQL Scripts. We already have database in sql server and database backup file .

DECLARE @DbName nvarchar(50)
SET @DbName = N'TestDB'
DECLARE @EXECSQL varchar(max)
SET @EXECSQL = ''
SELECT @EXECSQL = @EXECSQL + 'Kill ' + Convert(varchar, SPId) + ';'
FROM MASTER..SysProcesses
WHERE DBId = DB_ID(@DbName) AND SPId  =@@SPId
EXEC(@EXECSQL)

ALTER DATABASE [TestDB] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO

RESTORE DATABASE [TestDB] FROM DISK = 'D:\backup\TestDB.bak' WITH REPLACE 
GO

Thanks for reading. :)