Monday, 18 March 2019

How to take all database offline at one in SQL Server

Hi All,

Today, we are going to learn how we can take all the Databases offline at one time by using SQL scripts. 

Below are the SQL scripts. 


DECLARE @dbName SYSNAME
,@query VARCHAR(MAX);
DECLARE cursor_db CURSOR
FOR
SELECT name
FROM sys.databases
WHERE owner_sid <> 0x01;
OPEN cursor_db;
WHILE 1 = 1
BEGIN
FETCH NEXT
FROM cursor_db
INTO @dbName;
IF @@FETCH_STATUS <> 0
BREAK;
SET @query = N'ALTER DATABASE [' + @dbName + N'] SET OFFLINE WITH NO_WAIT';
EXEC (@query);
END;
CLOSE cursor_db;
DEALLOCATE cursor_db;


Thanks for reading.


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. :) 

Friday, 24 March 2017

Data Type in JavaScript 

JavaScript has five primitive data type.

1  Number
2  String
3  Boolean
4  Undefined
5  Null

Any data type other than above 5 types is called object.  

In javascript there are two types to object.

  1. Build in object
  2. Custom object

Build in Object :  Examples include array, date etc. In below example we have create the object of date by using date constructor.

    var date= new Date();
    alert(date.getDate);
    alert(date.getFullYear);


Custom objects : In JavaScript we don't have classes. We use function instead of classes.
In JavaScript there are two ways to create a custom object.

1. Constructor function
2. Literal notation

Constructor Function

<script type="text/javascript">
    function Student(firstName, lastName)
    {
       this.firstName = firstName;
       this.lastName = lastName;

       this.getFullName = function ()
       {
           return this.firstName + " " + this.lastName;
       }
    }

    var student= new Student("Jitendra", "Kachhi");

    document.write("First Name :" + student.firstName + "<br/>");
    document.write("Last Name : " + student.lastName + "<br/>");
    document.write("Full Name :" + student.getFullName() + "<br/>");
</script>

literal Notation

<script type="text/javascript">
    var student=
    {
       firstName: "Jitendra",
       lastName: "Kachhi",

       FullName: function ()
       {
           return this.firstName + " " + this.lastName;
       }
    }

    document.write("FirstName = " + student.firstName + "<br/>");
    document.write("LastName = " + student.lastName + "<br/>");
    document.write("FullName = " + student.FullName() + "<br/>");
</script>

Note:- literal Notation will have only single object(singleton), if we want to create multiple object use Constructor Function.


Thanks you for reading.

Thursday, 11 September 2014

Default Scope of Class In C# Dot.net?





Hi All,  
Today i am going to explain the default scope of class  in C# .  
default scope of  class is internal, 
Class can  be public either internal , it can never be Private or protected  and protected Internal.  
In order to understand ,create the console Application.



















Go to Object Browser (Ctrl+Alt+j) here we will see the default scope of class.






















   Class can be Public also, but it can never be protected  , Private and  protected internal.
















So let me clarify "Default scope of class is internal" class can be public and internal but it can never be a protected  , private and protected  internal.

Happy coding...  
 

Access modifiers in C#

Today i am going to explain what is access modifiers in C#.


One of the most  favorite question of interviewer.  
What is modifiers?
Different types of modifiers  and different between them  ?

Access modifiers
Access modifiers are keywords used to specify the declared accessibility of a member or a type.
In C# there are 5 different types of Access Modifiers.

Public
-No restrictions to access
-The type or member can be accessed by any other code in the same assembly or another assembly that references it.

protected

-Access is limited to within the class definition and any class that inherits from the class.
-The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class.

internal
-Access is limited exclusively to classes defined within the current project assembly.
-The type or member can be accessed only by code in the same class or struct.

private
-Access is limited to within the class definition; This is the default access modifier type if none is formally specified.
-The type or member can be accessed by any code in the same assembly, but not from another assembly.

protected internal
protected internal member enjoy dual effect.it is accessible anywhere in the project as well as if that class is inherit one other class and that is in other project then only it can be accessible to other project also.

Go to live Example here.

Point to be notice  here
we can access these member objpublic objinternal and  objprotectedinternal in program class we can not access the private member outside the class and we can also not  access the protected member with derived class. In Order to access the protected member with derived class we have to create the object of derived  class.
I have create the object of Program class.that object can access the protected  member. because protected definition saying "It can be access with his derived class"
many of developer got confused in protected modifiers just because we have to create  object of derived  class.

private modifiers  saying "The type or member can be accessed only by code in the same class or struct."

Please find the code below.
class Fristclass
    {
        public int objpublic;
        private int objprivate;
        protected int objprotected;
        internal int objinternal;
        protected internal int objprotectedinternal;

        void show()
        {
            Console.WriteLine(objprivate); // private can access inside  same class or struct
        }
    }
    class Program:Fristclass
    {
        static void Main(string[] args)
        {
            Fristclass objclass = new Fristclass();
            Console.WriteLine(objclass.objinternal); // it can be current project assembly and same class and struct also
            Console.WriteLine(objclass.objprotectedinternal); // one other class and that is in other project then only it can be accessible to other project also.
            Console.WriteLine(objclass.objpublic); // no limit of access 



            // for protected and
            Program programclassobj = new Program();
            Console.WriteLine(programclassobj.objprotected);  // It can be access with his drived class
            Console.WriteLine(programclassobj.objprotectedinternal); // one other class and that is in other project then only it can be accessible to other project also
        }
    }

Happy coding....

Friday, 5 September 2014

Mobile number validation by using jquery

Hi Guys ,

In this post we are going to learn how to validate mobile number by using jquery 

Below is the jquery mobile, validation regular expression, mobile validation jquery regular expression which is for checking mobile digit number.



$(document).ready(function() {
    $('#textboxid').blur(function(e) {
        if (validateMobile('textboxid')) {
           alert('valid');
        }
        else {
            alert('invalid');
        }
    });
});

function validateMobile(txtPhone) {
    var a = document.getElementById(txtPhone).value;
    var filter = /^((\+[1-9]{1,4}[ \-]*)|(\([0-9]{2,3}\)[ \-]*)|([0-9]{2,4})[ \-]*)*?[0-9]{3,4}?[ \-]*[0-9]{3,4}?$/;
    if (filter.test(a)) {
        return true;
    }
    else {
        return false;
    }
}