Simplest way to restore MSSQL Server database

Here’s a simplest way I found (so far) to restore a database in MS SQL Server. First part lists “logicalnames” from the backup that you want to restore. Modify the path so it points to the actual path where your backup file is:

RESTORE FILELISTONLY FROM DISK = N'C:\[path]\[db_name_backup].bak'
 GO

This shows LogicalName and PhysicalName of the data and log backup files, which have to be used in the following script:

RESTORE DATABASE [db_name]
 FROM DISK = N'C:\[path]\[db_name_backup].bak'
 WITH FILE = 1,
 MOVE N'[data_file_logical_name]' TO N'C:\[restored_db_path]\[data_file_name].mdf',
 MOVE N'[log_file_logical_name]' TO N'C:\[restored_db_path]\[log_file_name].ldf',
 NOUNLOAD,
 STATS = 10
 GO

That’s it. Pretty simple, isn’t it?



How to delete all stored procedures from MSSQL database using cursor

Here is a code for deleting all stored procedures in SQL Server database using cursor. DECLARE @name varchar(500) DECLARE @sql varchar(max) SET @sql = ” DECLARE cur CURSOR FOR SELECT [name] FROM sys.procedures OPEN cur FETCH NEXT FROM cur INTO @name WHILE @@fetch_status = 0 BEGIN SET @sql = ‘DROP PROC ‘ + @name PRINT […]

How to close all connections to a MSSQL database

This script closes all connections to MS SQL database USE master; GO ALTER DATABASE dbName SET SINGLE_USER WITH ROLLBACK IMMEDIATE; GO ALTER DATABASE dbName SET MULTI_USER; GO

Animated iPhone-style ImageButton with Silverlight 4

In this article I am presenting a way to create animated iPhone-style ImageButton control in Silverlight 4. Button will have icon on it, rounded corners and will zoom-in/zoom-out on hover. It will be done programmatically, with very minimum amount of XAML. I start with creating ImageButton class. I use ButtonBase as base class: I want […]

Using Sets in .Net

Great post by James Michael Hare I came across about using Sets in .Net. Definitely worth taking a look. http://geekswithblogs.net/BlackRabbitCoder/archive/2011/02/03/c.net-little-wonders-the-useful-but-overlooked-sets.aspx

Next Page »