Friday, 27 May 2011

SQL Query to Take back up of Database

SQL Query to Take back up of Database 



sp_helpdb reportserver
go
sp_helpdb reportservertempdb

backup database reportserver to disk='D:\scripts\ssrs\reportserver.bak'  with init, stats=1
go
backup database reportservertempdb to disk='D:\scripts\ssrs\reportservertempdb.bak'  with init, stats=1



Useful javascripts for MS CRM

useful javascripts for MS CRM


From this link you can get very Useful javascript to use in CRM.



Contains topics like:

Replacing the content of an IFRAME
Changing the title of a CRM form
Changing the label of a field at runtime
Changing the colour of a single option in a picklist
Disabling a form at runtime
Automatically changing the value of a text field to capitals
Displaying a picture in a CRM form, using a text field to store the data source
Modifying the color of disabled form fields

and many more......

Add/Remove values from Drop Down box at Run Time in MSCRM


Add/Remove values from Drop Down box at Run Time in MSCRM

//Write this code on Change Event of Main Drop Down Box, It will change the value in second drop down.

crmForm.all.leb_subcategoryoftopup.remove(0);
crmForm.all.leb_subcategoryoftopup.remove(1);
crmForm.all.leb_subcategoryoftopup.remove(2);
crmForm.all.leb_subcategoryoftopup.remove(3);
crmForm.all.leb_subcategoryoftopup.remove(4);

if(crmForm.all.leb_reasonfortopup.DataValue <5){
crmForm.all.leb_subcategoryoftopup.disabled=true;
}
else
{
crmForm.all.leb_subcategoryoftopup.disabled=false;


if(crmForm.all.leb_reasonfortopup.DataValue ==5)
{
crmForm.all.leb_subcategoryoftopup.AddOption("Smile Call Offer", 1);
crmForm.all.leb_subcategoryoftopup.AddOption("Complaint Compensation", 2);
crmForm.all.leb_subcategoryoftopup.AddOption("Promo Credit", 3);
}

if(crmForm.all.leb_reasonfortopup.DataValue ==6)
{
crmForm.all.leb_subcategoryoftopup.AddOption("False Answer refund", 4);
crmForm.all.leb_subcategoryoftopup.AddOption("Expired Balance Transfer", 5);
crmForm.all.leb_subcategoryoftopup.AddOption("Lost/Stolen Balance Transfer", 6);
crmForm.all.leb_subcategoryoftopup.AddOption("Voucher Error/Blocked", 7);
}

if(crmForm.all.leb_reasonfortopup.DataValue ==7)
{
crmForm.all.leb_subcategoryoftopup.AddOption("Expired Balance Transfer", 8);
crmForm.all.leb_subcategoryoftopup.AddOption("Balance Correction", 9);
crmForm.all.leb_subcategoryoftopup.AddOption("Online Top-up Decline", 10);
}



}

Wednesday, 25 May 2011

Create Separate File Group to create Indexing

Here are the steps to create separate file group for indexing on any table. We can use different file location (on hard disk) for file group to avoid the problem of space on hard disk.

step 1: 
Right Click Database -> Properties

Step 2: 
Click on file groups option - > Add  -> Enter some file name

Step 3:

Click on Files -> Add -> Enter some Database file name and Select FileGroup created in above Step-2

Step 4: 
Click Ok Or Click on Script on the top to create SQL Script and then run through that Script.
It will take some time.

Step 5 : Index Creation:
Go to Database - > Indexes - > Create New Index:
Enter some index name - > Click on Add -> select the field name




Step 6:
Click on Storage from left side.
Next to filegroup option select the filegroup created in step 2




Step 6:
Click Ok Or click on Script on the top to generate the Script and then run that script.

It will take some time to finish indexing depending on the size of database.





Tuesday, 17 May 2011

Update Statistics to Improve performance

You can improve query performance by using UPDATE STATISTICS or the stored proceduresp_updatestats to update statistics more frequently than the default updates.


Updating statistics ensures that queries compile with up-to-date statistics. However, updating statistics causes queries to recompile. We recommend not updating statistics too frequently because there is a performance tradeoff between improving query plans and the time it takes to recompile queries. The specific tradeoffs depend on your application. UPDATE STATISTICS can use tempdb to sort the sample of rows for building statistics.


USE AdventureWorks2008R2;
GO
EXEC sp_updatestats 

TO CREATE STATISTICS SCRIPT FOR ALL DATABASES on a DATABASE SERVER:
CREATE PROCEDURE SPUpdateStats
AS Set Nocount on Declare db Cursor For Select distinct(Databasename) as Name FROM T_TableReindexing(nolock) --Select name from master.dbo.sysdatabases where name in ('dbmonitor') and name --not in ('master','TempDB', 'msdb', 'model') Declare @dbname varchar(60) Declare @execmd nvarchar(150) Open db Fetch Next from db into @dbname While @@Fetch_status=0 begin if @dbname is null Begin Print 'null Value' Return end else Begin PRINT '###########################################################################' PRINT 'Update Statistics in ' + @dbname SELECT @execmd = 'USE ' + @dbname + ' EXEC sp_updatestats' Print (@execmd) PRINT '' End Fetch Next from db into @dbname end Close db Deallocate db

BCP Command


Open the Command Prompt and use the following command for quick and fast backup.

Selected Query:


BCP "select * from GBRVIEW.dbo.CDR_0(nolock) where charging_timestamp between '2011-05-01' and '2011-05-31 23:59:59.997' and CDR_SPECIFIC_ID not in (select CDR_SPECIFIC_ID from GBRVIEW.dbo.cdr201105(nolock))" queryOut V:\May_CDR_0_Archive\GBRVIEW_CDR_PartCDRMay11_MISSING2_May11.txt -c -T -S LEB-ODSMSSQL2




Whole table without any condition:

BCP gbrview.dbo.cdr201105 Out T:\cdrbACKUP\GBRCDR201105.txt -c -T -S LEB-ODSMSSQL2