Jagadeeps’s Blog

Recoviring a suspect database with out a backup in sql server.

Posted by: jagadeep suggula on: March 29, 2010

I was struck with a SQL Server database which is on suspect mode and need to recover it without having any recent backups in hand. I Googled for quite a long time and found these steps to bring back the database to online state without losing any data. I found these steps very useful and I hope they will be useful to others who face similar problem

Step 1:
Open SQL Server Management Studio and connect to the SQL Server. Make sure that your current database is set to master

Step 2:
Clear the suspect mode of the database using sp_resetstatus DatabaseName. This will clear the suspect flag and make the database available online

Step 3:
Change the database status to Emergency using the following command. Emergency mode allows you to access the databases as normal but with no consistency guarantee. This option also allows us to export the table data so that we can minimize the damage.

ALTER DATABASE DatabaseName SET EMERGENCY;

Step 4:
Restrict database to single user by changing the access mode as mentioned below
ALTER DATABASE DatabaseName SET SINGLE_USER;

Step 5:
Run the CHECKDB command with “REPAIR_ALLOW_DATA_LOSS” option. This option should be tried as last option as it always behaves the way it is named. We are not sure of what data it removes.

DBCC CHECKDB (DatabaseName, REPAIR_ALLOW_DATA_LOSS) WITH NO_INFOMSGS, ALL_ERRORMSGS;

Even though the step 4 is expected to result in data loss while repairing the database, I was lucky to restore the database without any loss. My job would have been much easier if the admin of the database server followed few general guidelines that allow recovery of database in case of any unexpected failures. Here are the few of them

* Backup your data frequently. (once in two days or daily or even more frequent depending on your needs)
* Have multiple backups. Move the backups to external drives or tapes frequently
* Validate that your backups are good by performing trial restores to alternate server
* Run CHECKDB regularly if possibly in your case, to know how long it regularly takes

Read more: http://www.techdreams.org/microsoft/how-to-recover-a-sql-server-database-from-in-suspect-mode/3696-20100224#ixzz0jY7Mjvg6

How to run SQL Profiler without sysadmin rights?

Posted by: jagadeep suggula on: January 29, 2010

In SQL Server 2000, to run SQL Profiler the sysadmin needs to grant permissions to the user running the trace. In SQL Server 2005 and 2008, the option exists of granting permissions to Profiler so that users do not need to be a member of the sysadmin group by using the code below:

USE master
GO
GRANT ALTER TRACE TO username;
GO

If the permission needs to be revoked, use the code below:

USE master
GO
DENY ALTER TRACE TO username;
GO

Query to Update the Gender Column in a Table

Posted by: jagadeep suggula on: January 28, 2010

UPDATE Table
SET Gender =CASE WHEN Gender =’M’ THEN ‘Male’
WHEN Gender =’F’ THEN ‘Female’
END

With the above query we can update all the columns at a time.

My Ping Box

Posted by: jagadeep suggula on: January 11, 2010

Number of clustered and Non-clustered indexes a table can have

Posted by: jagadeep suggula on: May 14, 2009

A table can have 249 Non-Clustered indexes, and only one clustered index.

The for having only one clustered index for a table is, the clustered index physically sorts the column values, and the data columns can be sorted in only one order Hence we can say that a table cannot have more than one clusterd index.

Hide actual url in address-bar using iframe

Posted by: jagadeep suggula on: April 13, 2009

Do you want to hide the actual URL in the address-bar? Do you want to display the same url throughout the website? Then here is the tips for you do the same in your website. Just display the same URL i.e http://www.your-site.com throughout your website in address bar, no matter if you in the page http://www.your-site.com/aboutus.html.

Click here for Live Demo

New books Uploaded

Posted by: jagadeep suggula on: March 4, 2009

   
 
          Hello Guys, i have uploaded new books in the SHAREPOINT SECTION

Visit this site

Posted by: jagadeep suggula on: February 16, 2009

 
 

  >>If you have a table in a database and you would like to copy the table to another database, then use this query

       Select * into AdventureWorks.dbo.Employees_New from Nothwind.dbo.Employees

      Executing the above query will copy your table to a new database.
      Just remember that using this query will only transfer the schema and data. It does not transfer the indexes, foreign keys.
      If you want to transfer all the objects from one database to another, open Sql Server Management Studio >
      Right click on your database > All Tasks > Generate SQL Scripts. Then run these scripts against the new database.
    To Transfer both schema and data
     To copy both data and schema, use the Microsoft SQL Server Database Publishing Wizard 1.1.
     This tool works for both SQL 2000 and SQL 2005 and generates a single SQL script file which can be used to recreate
     a database (both schema and data).

     

To Set the Cursor Focus to a Textbox when the page loads

Posted by: jagadeep suggula on: February 10, 2009

 
  >>To set the Cursor Focus to a Textbox when the page loads, just a piece of code in your Page_Load

       this.Page.Form.DefaultFocus = TextBoxID.ClientID;


  • None
  • ornanocoipusa: good topic http://bradhsfxga.tumblr.com/ - برامج http://bradhsfxga.tumblr.com/ - برامž
  • Abdul Sakkeel: can you tell the code for hiding URL
Follow

Get every new post delivered to your Inbox.