Tuesday, March 12, 2013

Script for creating a folder & taking a backup up in that folder


declare @name varchar(500)
declare @q nvarchar(MAX)
declare @foldername varchar(500)
set @foldername = 'D:\db backup\dbbackup_' + CONVERT(varchar,getdate(),110) + ''
--EXEC master.sys.xp_dirtree @DataPath
EXEC master.dbo.xp_create_subdir @foldername

set @name = @foldername + '\next_' + CONVERT(varchar,getdate(),110) + '.bak'
set @q = ' BACKUP DATABASE [Next] TO  DISK = N''' + @name + ''' WITH NOFORMAT, NOINIT,
 NAME = N''Next-Full Database Backup'', SKIP, NOREWIND, NOUNLOAD,  STATS = 10'
print @q
exec sp_executesql @q

set @name = @foldername + '\Mirror_test_' + CONVERT(varchar,getdate(),110) + '.bak'
set @q = ' BACKUP DATABASE [Mirror_test] TO  DISK = N''' + @name + ''' WITH NOFORMAT, NOINIT,
 NAME = N''Mirror_test-Full Database Backup'', SKIP, NOREWIND, NOUNLOAD,  STATS = 10'
print @q
exec sp_executesql @q

Sunday, February 10, 2013

Check Box in Crystal Report or MicorSoft Report.


The following Example shows how to Place a Check Box in Crystal Report

Steps to be performed :

1. Expand Field Explorer

2. Go To Formula's-> Right Click on that And New Formula

3. Give a Name to that Formula Editor

4. Now Editor will be displayed

5. In that Editor place the below Formula
if{Table.FieldName} = true Then
Chr(254)
Else
Chr(168)


6. Close the Editor it will show save Prompt save the formula

7. Drag and drop your formula field to your crystal report
Right Click to format Object for that Formula-> Select Format Object

8. Go to Fonts Tab and Set Font as 'Wingdings' and Press Ok

9. Now check it will display if value is true then checked check box else un-checked checkbox.

Friday, May 25, 2012

New Elements in HTML5

The internet has changed a lot since HTML 4.01 became a standard in 1999.
Today, some elements in HTML 4.01 are obsolete, never used, or not used the way they were intended to. These elements are removed or re-written in HTML5.
To better handle today's internet use, HTML5 includes new elements for better structure, better form handling, drawing, and for media content.

http://www.w3schools.com/html5/html5_new_elements.asp

Wednesday, May 23, 2012

Diffrence between Sql 2005 and 2008

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=107186

Main Features provided in Sql 2008:
Date and time are seperately used for date and time datatype,geospatial and timestamp with internal timezone
is used.

Table datatype introduced.
Can encrypt the entire database introduced in 2008.
Central Management Server(CMS) is Introduced.  

Diffrence between 3-Tier and mvc-vs-mvp-vs-mvvm

http://nirajrules.wordpress.com/2009/07/18/mvc-vs-mvp-vs-mvvm/

A fundamental rule in a three-tier architecture is the client tier never communicates directly with the data tier; in a three-tier model all communication must pass through the middleware tier. Conceptually the three-tier architecture is linear. However, the MVC architecture is triangular: the View sends updates to the Controller, the Controller updates the Model, and the View gets updated directly from the Model. 

Tuesday, May 1, 2012

Difference between Function and Stored procedure

The following are the differences between a User Defined Function and a Stored Procedure in SQL Server

  1. Stored Procedure support deffered name resolution where as functions do not support deffered name resolution.
  2. User Defined Function can be used in a select statement where as you cannot use a stored procedure in a select statement.
  3. UDF’s cannot return Image, Text where as a StoredProcedure can return any datatype.
  4. In general User Defined Functions are used for computations where as Stored Procedures are used for performing business logic.
  5. UDF should return a value where as Stored Procedure need not.
  6. User Defined Functions accept lesser number of input parameters than Stored Procedures. UDF can have upto 1023 input parameters where as a Stored Procedure can have upto 21000 input parameters.
  7. You cannot use non-deterministic built-in functions in UDF’s. For example functions like GETDATE() etc can not be used in UDFs, but can be used in Stored Procedures.
  8. Temporary Tables can not be used in a UDF where as a StoredProcedure can use Temporary Tables.
  9. UDF can not Execute Dynamic SQL where as a Stored Procedure can execute Dynamic SQL.
  10. User Defined Function does not support error handling where as Stored Procedure support error handling. RAISEERROR or @@ERROR are not allowed in UDFs.

Monday, April 23, 2012

SQL Server script to rebuild all indexes for all tables and all databases

DECLARE @Database VARCHAR(255)   DECLARE @Table VARCHAR(255)  DECLARE @cmd NVARCHAR(500)  DECLARE @fillfactor INT

SET
@fillfactor = 90
DECLARE DatabaseCursor CURSOR FOR 
SELECT
name FROM MASTER.dbo.sysdatabases   WHERE name NOT IN ('master','msdb','tempdb','model','distribution')   ORDER BY 1 
OPEN DatabaseCursor 
FETCH NEXT FROM DatabaseCursor INTO @Database  WHILE @@FETCH_STATUS = 0  BEGIN 

   SET
@cmd = 'DECLARE TableCursor CURSOR FOR SELECT ''['' + table_catalog + ''].['' + table_schema + ''].['' +
  table_name + '']'' as tableName FROM '
+ @Database + '.INFORMATION_SCHEMA.TABLES
  WHERE table_type = ''BASE TABLE'''  

  
-- create table cursor 
  
EXEC (@cmd) 
  
OPEN TableCursor  

  
FETCH NEXT FROM TableCursor INTO @Table  
  
WHILE @@FETCH_STATUS = 0  
  
BEGIN  

       IF
(@@MICROSOFTVERSION / POWER(2, 24) >= 9)
      
BEGIN
          
-- SQL 2005 or higher command
          
SET @cmd = 'ALTER INDEX ALL ON ' + @Table + ' REBUILD WITH (FILLFACTOR = ' + CONVERT(VARCHAR(3),@fillfactor) + ')'
          
EXEC (@cmd)
      
END
       ELSE
       BEGIN
          
-- SQL 2000 command
          
DBCC DBREINDEX(@Table,' ',@fillfactor) 
      
END

       FETCH
NEXT FROM TableCursor INTO @Table  
  
END  

   CLOSE
TableCursor  
  
DEALLOCATE TableCursor 

  
FETCH NEXT FROM DatabaseCursor INTO @Database  END 
CLOSE
DatabaseCursor   DEALLOCATE DatabaseCursor