Sunday, April 7, 2013

Sql Sqerver : Generate Conditional Table Data Script

“Sql Server 2005:Generate Tables Data Script ” and “Sql Server 2008:Generate Data Script” we have discussed methods to generate table data script for schema based script for Sql Server 2005 and specific table’s data script for Sql Server 2008 respectively.

On suggestion of few friends following script will generate table data script based on your given conditions. This script is useful to generate script for only required records of a targeted table data and not the whole data for a table.
Following are four steps to achieve our goal.
1.       Create function to get all columns name of targeted table
2.       Create function to get values for all columns of targeted table
3.       Create a store procedure, to group our queries for future use.
4.       Execute store procedure with following parameters
a.       Schema Name
b.      Table Name
c.       Condition with WHERE clause
--------------------------------------------------
--STEP (1)
--------------------------------------------------
CREATE FUNCTION [dbo].[fnc_GetColumnsByCommas]
    (
      -- Add the parameters for the function
      @schemaName VARCHAR(50),
      @tableName VARCHAR(50)
    )
RETURNS VARCHAR(4000)
AS BEGIN

    DECLARE @column VARCHAR(2000),
        @columnS VARCHAR(4000),
        @i INT
    SET @i = 0
    SET @column = ''
    SET @columnS = ''

    DECLARE Cur_Columns CURSOR STATIC
        FOR SELECT  sys.columns.name
            FROM    sys.schemas
                    INNER JOIN sys.objects ON sys.schemas.schema_id = sys.objects.schema_id
                    INNER JOIN sys.columns ON sys.columns.object_id = sys.objects.object_id
                    INNER JOIN sys.types ON sys.columns.user_type_id = sys.types.user_type_id
            WHERE   sys.types.name <> 'timestamp'
                    AND sys.objects.type = 'U'
                    AND sys.objects.name = @tableName
                    AND sys.schemas.name = @schemaName
            ORDER BY sys.columns.column_id
    OPEN Cur_Columns
    FETCH FIRST FROM Cur_Columns INTO @column
    WHILE @@FETCH_STATUS = 0
        BEGIN
            IF @i = 0
                SET @columnS = '[' + @column + ']'
            ELSE
                SET @columnS = @columnS + ',' + '[' + @column + ']'
            SET @i = @i + 1

            FETCH NEXT FROM Cur_Columns INTO @column
        END

    CLOSE Cur_Columns
    DEALLOCATE Cur_Columns

 -- Return the result of the function
    RETURN @columns

   END 


--------------------------------------------------
--STEP (2)
--------------------------------------------------
CREATE FUNCTION [dbo].[fnc_GetColumnsForValueByCommas]
    (
      -- Add the parameters for the function here
      @schemaName VARCHAR(50),
      @tableName VARCHAR(50)
    )
RETURNS VARCHAR(4000)
AS BEGIN
 
    DECLARE @column VARCHAR(4000),
        @typeName VARCHAR(500),
        @columnS VARCHAR(2000),
        @ColStart VARCHAR(50),
        @ColEnd VARCHAR(50),
        @i INT

    SET @i = 0

    SET @column = ''
    SET @columnS = ''

    DECLARE Cur_Columns CURSOR STATIC
        FOR SELECT  sys.columns.name,
                    sys.types.name
            FROM    sys.schemas
                    INNER JOIN sys.objects ON sys.schemas.schema_id = sys.objects.schema_id
                    INNER JOIN sys.columns ON sys.columns.object_id = sys.objects.object_id
                    INNER JOIN sys.types ON sys.columns.user_type_id = sys.types.user_type_id
            WHERE   sys.types.name <> 'timestamp'
                    AND sys.objects.type = 'U'
                    AND sys.objects.name = @tableName
                    AND sys.schemas.name = @schemaName
            ORDER BY sys.columns.column_id


    OPEN Cur_Columns
    FETCH FIRST FROM Cur_Columns INTO @column, @typeName
    WHILE @@FETCH_STATUS = 0
        BEGIN
            IF @typeName = 'text'
                OR @typeName = 'uniqueidentifier'
                OR @typeName = 'varbinary'
                OR @typeName = 'smalldatetime'
                OR @typeName = 'char'
                OR @typeName = 'datetime'
                OR @typeName = 'varchar'
                OR @typeName = 'date'
                OR @typeName = 'time'
                BEGIN
                    SET @ColStart = ' ISNULL(CHAR(39) + CAST ( '  
                    SET @ColEnd = ' AS VARCHAR(MAX))+ CHAR(39),''NULL'') '
                END
            ELSE
                IF @typeName = 'nvarchar'
                    OR @typeName = 'ntext'
                    OR @typeName = 'nchar'
                    BEGIN
                        SET @ColStart = 'ISNULL( ''N''+CHAR(39)+ CAST ( ' 
                        SET @ColEnd = ' AS NVARCHAR(MAX)) + CHAR(39),''NULL'') '
                    END
                ELSE
                    BEGIN 
                        SET @ColStart = 'ISNULL(CAST ( ' 
                        SET @ColEnd = ' AS VARCHAR(MAX)), ''NULL'') '
                    END

            IF @i = 0
                SET @columnS = @ColStart + @column + @ColEnd
            ELSE
                SET @columnS = @columnS + '+'',''+' + @ColStart + @column
                    + @ColEnd
            SET @i = @i + 1

            FETCH NEXT FROM Cur_Columns INTO @column, @typeName
        END

    CLOSE Cur_Columns
    DEALLOCATE Cur_Columns


-- Return the result of the function
    RETURN @columns

   END 
--------------------------------------------------
--STEP (3)
--------------------------------------------------
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[proc_CreateInsertStatmentsBySchema]
    (
      -- Add the parameters for the function here
      @SchemaName VARCHAR(50),
      @TableName VARCHAR(50),
      @Condition VARCHAR(2000)
    )
AS
    BEGIN

        DECLARE @tbID INT,
            @tbNAME VARCHAR(50),
            @tbColumn VARCHAR(4000),
            @tbColumnforVal VARCHAR(4000),
            @SQLstr VARCHAR(4000),
            @label VARCHAR(500),
            @Count INT

        SELECT  @tbNAME = '[' + sys.schemas.name + '].[' + sys.objects.name
                + ']',
                @tbColumn = dbo.fnc_GetColumnsByCommas(@schemaName,
                                                       sys.objects.name),
                @tbColumnforVal = dbo.fnc_GetColumnsForValueByCommas(@schemaName, sys.objects.name)
        FROM    sys.schemas
                INNER JOIN sys.objects ON sys.schemas.schema_id = sys.objects.schema_id
        WHERE   sys.objects.type = 'U'
                AND sys.schemas.name = @schemaName
                AND sys.objects.name = @TableName

        SET @SQLstr = 'SELECT ' + CHAR(39) + 'INSERT INTO ' + @tbNAME + '  ('
            + @tbColumn + ')  VALUES ( ''+' + @tbColumnforVal
            + ' +'')'' FROM ' + @tbNAME + @Condition
        EXEC ( @SQLstr
            )

    END

--------------------------------------------------
STEP (4)Execute store procedure with “Result to Text” option

--------------------------------------------------  
    Use AdventureWorks
    EXEC [dbo].[proc_CreateInsertStatmentsBySchema] 'HumanResources',
        'Department', ' WHERE DepartmentID <10 span="">
I got a reference from one of wonderfull site i.e
  • http://connectsql.blogspot.com/2010/11/sql-server-management-studio-generate.html
  • http://connectsql.blogspot.com/2009/09/generate-tables-data-script.html

Friday, February 8, 2013

HTML,XHTML Tag Attributes Information

<label> Tag Attributes

Attribute Description
forThe for attribute is used to associate the label with the control. This is accomplished by setting the value of the for attribute to match the control's id attribute.
idThe id attribute assigns a unique name to a tag. This allows style sheets or scripts to reference the tag. 
classThe class attribute assigns a class name to a tag. The class name does not need to be unique. More than one tag can have the same class name. This allows style sheets or scripts to reference multiple tags with a single class name. 
styleThe style attribute specifies styles for the tag. For Cascading Style Sheets (CSS), the syntax is name:value. Each name:value pair is separated by semicolons. 
titleThe title attribute specifies additional information about the tag. It is common for browsers to display the title when the pointing device stops over the object. 
accesskeyThe accesskey specifies a shortcut key for a tag. The action that is taken when an access key is invoked depends on the tag and may also depend on the browser. For example, if it is used with an <a> tag, some browsers may follow the link when the access key is invoked and other browsers may give focus to the link. 
onblurThe onblur attribute specifies a script to be run when the tag loses focus. 
onfocusThe onfocus attribute specifies a script to be run when the tag loses focus. 
onclickThe onclick attribute specifies a script to be run when the object is clicked with a mouse or other pointing device. 
ondblclickThe ondblclick attribute specifies a script to be run when the object is double clicked with a mouse or other pointing device. 
onkeydownThe onkeydown attribute specifies a script to be run when a key is pressed down. 
onkeypressThe onkeypress attribute specifies a script to be run when a key is pressed and released. 
onkeyupThe onkeyup attribute specifies a script to be run when a key is released. 
onmousedownThe onmousedown attribute specifies a script to be run when the mouse button, or other pointing device button, is pressed while over the object. 
onmousemoveThe onmousemove attribute specifies a script to be run when the mouse, or other pointing device, is moved while it is over the object. 
onmouseoutThe onmouseout attribute specifies a script to be run when the mouse, or other pointing device, is moved away from an object after being over it.
onmouseoverThe onmouseover attribute specifies a script to be run when the mouse, or other pointing device, is moved onto the object. 
onmouseupThe onmouseup attribute specifies a script to be run when the mouse button, or other pointing device button, is released while over the object.
dirThe dir attribute tells the browser whether the text should be displayed from left-to-right or right-to-left. It does not reverse the direction of the characters, like the <bdo> tag does, but it can help the browser to determine if the text should be aligned on the left side or the right side. 
langThe lang attribute specifies a language. This attribute can help the browser to correctly display text. This attribute can also be useful for braille translation software, speech synthesizers, dictionary definitions, etc. 
xml:langThe xml:lang attribute specifies a language for XHTML documents. This attribute can help the browser to correctly display text. This attribute can also be useful for braille translation software, speech synthesizers, dictionary definitions, etc. 

Note: XHTML only.

For more detail please visit external site i.e.

Tuesday, January 22, 2013

Operator Overloadiong in C#

All unary and binary operators have pre-defined implementations, that are automatically available in any expressions. In addition to this pre-defined implementations, user defined implementations can also be introduced in C#. The mechanism of giving a special meaning to a standard C# operator with respect to a user defined data type such as classes or structures is known as operator overloading. Remember that it is not possible to overload all operators in C#. The following table shows the operators and their overloadability in C#.

Operators Overloadability 
+, -, *, /, %, &, |, <<, >> All C# binary operators can be overloaded.
+, -, !,  ~, ++, --, true, false All C# unary operators can be overloaded.
==, !=, <, >, <= , >= All relational operators can be overloaded, but only as pairs.
&&, || They can't be overloaded.
[] (Array index operator) They can't be overloaded.
() (Conversion operator) They can't be overloaded.
+=, -=, *=, /=, %= These compound assignment operators can be overloaded. But in C#, these operators are automatically overloaded when the respective binary operator is overloaded.
=, . , ?:, ->, new, is, as, sizeof These operators can't be overloaded in C#.
In C#, a special function called operator function is used for overloading purpose. These special function or method must be public and static. They can take only value arguments. The ref and out parameters are not allowed as arguments to operator functions. The general form of an operator function is as follows. 
public static return_type operator op (argument list)
Where the op is the operator to be overloaded and operator is the required keyword. For overloading the unary operators, there is only one argument and for overloading a binary operator there are two arguments. Remember that at least one of the arguments must be a user-defined type such as class or struct type. 
Overloading Unary Operators 
The general form of operator function for unary operators is as follows. 

public static return_type operator op (Type t)
{
    // Statements



Where Type must be a class or struct.
The return type can be any type except void for unary operators like +, ~, ! and dot (.) but the return type must be the type of 'Type' for ++ and - operators and must be a bool type for true and false operators. Also remember that the true and false operators can be overloaded only as pairs. The compilation error occurs if a class declares one of these operators without declaring the other. 
The following program overloads the unary - operator inside the class Complex 

// Unary operator overloading
// Author: murlid05@gmail.com
class Complex
{
    private int x;
    private int y;
    public Complex()
    {
    }
    public Complex(int i, int j)
    {
        x = i;
        y = j;
    }
    public void ShowXY()
    {
        Console.WriteLine("{0} {1}", x, y);
    }
    public static Complex operator -(Complex c)
    {
        Complex temp = new Complex();
        temp.x = -c.x;
        temp.y = -c.y;
        return temp;
    }
}

class MyClient
{
    public static void Main()
    {
        Complex c1 = new Complex(10, 20);
        c1.ShowXY(); // displays 10 & 20
        Complex c2 = new Complex();
        c2.ShowXY(); // displays 0 & 0
        c2 = -c1;
        c2.ShowXY(); // diapls -10 & -20
    }
}


Overloading Binary Operators  An overloaded binary operator must take two arguments; at least one of them must be of the type class or struct, in which the operation is defined. But overloaded binary operators can return any value except the type void. The general form of a overloaded binary operator is as follows. 

 public static return_type operator op (Type1 t1, Type2 t2)
{
    //Statements
}

//A concrete example is given below.

// Binary operator overloading
// Author: murlid05@gmail.com
class Complex
{
    private int x;
    private int y;
    public Complex() { }

    public Complex(int i, int j)
    {
        x = i;
        y = j;
    }
    public void ShowXY()
    {
        Console.WriteLine("{0} {1}", x, y);
    }
    public static Complex operator +(Complex c1, Complex c2)
    {
        Complex temp = new Complex();
        temp.x = c1.x + c2.x;
        temp.y = c1.y + c2.y;
        return temp;
    }
}

class MyClient
{
    public static void Main()
    {
        Complex c1 = new Complex(10, 20);
        c1.ShowXY(); // displays 10 & 20
        Complex c2 = new Complex(20, 30);
        c2.ShowXY(); // displays 20 & 30
        Complex c3 = new Complex();
        c3 = c1 + c2;
        c3.ShowXY(); // dislplays 30 & 50
    }
}


The binary operators such as = =, ! =, <, >, < =, > = can be overloaded only as pairs. Remember that when a binary arithmetic operator is overloaded, corresponding assignment operators also get overloaded automatically. For example if we overload + operator, it implicitly overloads the + = operator also. 
Operator Overloading & Inheritance 
Even though the overloaded operators are declared as static, they are inherited to the derived classes. Because operator declaration always requires the class or struct in which the operator is declared, to participate in the signature of the operator, it is jot possible for an operator declared in a derived class to hide an operator declared in a base class. Thus the new modifier is never required and there never permitted in an operator declaration.

class Complex
{
    private int x;
    private int y;
    public Complex()
    {
    }
    public Complex(int i, int j)
    {
        x = i;
        y = j;
    }
    public void ShowXY()
    {
        Console.WriteLine("{0} {1}", x, y);
    }
    public static Complex operator +(Complex c1, Complex c2)
    {
        Complex temp = new Complex();
        temp.x = c1.x + c2.x;
        temp.y = c1.y + c2.y;
        return temp;
    }
}
class MyComplex : Complex
{
    private double x;
    private double y;
    public MyComplex(double i, double j)
    {
        x = i;
        y = j;
    }
    public MyComplex()
    {
    }
    public new void ShowXY()
    {
        Console.WriteLine("{0} {1}", x, y);
    }
}
class MyClient
{
    public static void Main()
    {
        MyComplex mc1 = new MyComplex(1.5, 2.5);
        mc1.ShowXY();
        MyComplex mc2 = new MyComplex(3.5, 4.5);
        mc2.ShowXY();
        MyComplex mc3 = new MyComplex();
        //mc3 = mc1 + mc2;
        //mc3.ShowXY();
    }
}


Overloading Equality Operators 
Since all user defined classes, by default, inherit from Syste.object, they inherit the System.object.Equals() method. The default implementation of Equals() method provide a reference based comparison. But it is possible to override this method inside the user-defined class so that they can provide a value-based comparison. The following class is an example for a reference-based comparison of Equals() method.  

// Equals() Default Implementation
// Author: murlid05@gmail.com

class Complex
{
    private int x;
    private int y;
    public Complex()
    {
    }
    public Complex(int i, int j)
    {
        x = i;
        y = j;
    }
    public void ShowXY()
    {
        Console.WriteLine("{0} {1}", x, y);
    }
}
class MyClient
{
    public static void Main()
    {
        Complex c1 = new Complex(10, 20);
        c1.ShowXY(); // displays 10 & 20
        Complex c2 = new Complex(10, 20);
        c2.ShowXY(); // displays 10 & 20
        Complex c3 = c2;
        c3.ShowXY(); // dislplays 10 & 20
        if (c1.Equals(c2))
            Console.WriteLine("OK");
        else
            Console.WriteLine("NOT OK");
        if (c2.Equals(c3))
            Console.WriteLine("OK1");
    }
}
he above program on execution displays "NOT OK" and "OK1". That means the Equals() method by default do a reference comparison. Remember that the values of objects c1 and c2 are same. But they have different references. But in the case of c2 and c3, they refer to the same object on the memory.
But in C#, it is possible to override the Equals() method inside any user defined class as shown below, so that they can do a value-based comparison. 

// Equals() Overriding Default Implementation
// Author: murlid05@gmail.com

class Complex
{
    private int x;
    private int y;
    public Complex()
    {
    }
    public Complex(int i, int j)
    {
        x = i;
        y = j;
    }
    public void ShowXY()
    {
        Console.WriteLine("{0} {1}", x, y);
    }
    public override bool Equals(object o)
    {
        if ((Complex)o.x == this.x && (Complex)o.y == this.y)
            return true;
        else
            return false;
    }
    public override int GetHashCode()
    {
        return this.ToString().GetHashCode();
    }
}
class MyClient
{
    public static void Main()
    {
        Complex c1 = new Complex(10, 20);
        c1.ShowXY(); // displays 10 & 20
        Complex c2 = new Complex(10, 20);
        c2.ShowXY(); // displays 10 & 20
        Complex c3 = c2;
        c3.ShowXY(); // dislplays 10 & 20
        if (c1.Equals(c2))
            Console.WriteLine("OK");
        else
            Console.WriteLine("NOT OK");
        if (c2.Equals(c3))
            Console.WriteLine("OK1");
    }
}



Now the program displays both "OK" and "OK1" on the command prompt.
Remember that when we override the Equals() method inside a class, we will need to override GetHashCode() method also. 
Now let us see how we can override the operator = = and ! = so that they can do the comparisons.


// Overloading = = and ! = operators
// Author: murlid05@gmail.com
class Complex
{
    private int x;
    private int y;
    public Complex()
    {
    }
    public Complex(int i, int j)
    {
        x = i;
        y = j;
    }
    public void ShowXY()
    {
        Console.WriteLine("{0} {1}",x,y);
    }
    public override bool Equals(object o)
    {
        if((Complex)o.x == this.x && (Complex)o.y == this.y )
            return true;
        else
         return false;
    }
    public override int GetHashCode()
    {
        return this.ToString().GetHashCode();
    }
    public static bool operator = = (Complex c1, Complex c2)
    {
        return c1.Equals(c2);
    }
    public static bool operator ! = (Complex c1, Complex c2)
    {
        return ! c1.Equals(c2);
    }
}
class MyClient
{
    public static void Main()
    {
        Complex c1 = new Complex(10,20);
        c1.ShowXY(); // displays 10 & 20
        Complex c2 = new Complex(10,20);
        c2.ShowXY(); // displays 10 & 20
        Complex c3 = c2;
        c3.ShowXY(); // dislplays 10 & 20
        if(c1 = = c2)
            Console.WriteLine("OK");
        else if(c2 ! = c3)
            Console.WriteLine("OK1");   
        else
            Console.WriteLine("NOT OK");
    }
}


nstead of repeating the codes I just call the override Equals() method inside the operator functions. Remember that if we overload the = = operator inside a class or struct we must also override ! = operator. 

Summary 

  1. The user defined operator declarations can't modify the syntax, precedence or associatively of an operator. For example, a + operator is always a binary operator having a predefined precedence and an associatively of left to right.

  2.  User defined operator implementations are given preference over predefined implementations.

  3. Operator overload methods can't return void.

  4. The operator overload methods can be overloaded just like any other methods in C#. The overloaded methods should differ in their type of arguments and/or number of arguments and/or order of arguments. Remember that in this case also the return type is not considered as part of the method signature.

  5. emember that the capability to overload operators is not a requirement of the common language specification. Hence, not all .NET aware languages supports operator overloading.

  

The code uses the feature of Operator Overloading in C#. It shows how different operators are overloaded and can be used in a easy manner.

protected void Page_Load(object sender, EventArgs e)
    {
        Rectangle objRect1 = new Rectangle();
        Rectangle objRect2 = new Rectangle();
        Rectangle objRect3 = new Rectangle(10, 15);
        objRect1.Height = 15;
        objRect1.Width = 10;
        objRect2.Height = 25;
        objRect2.Width = 10;
        Console.WriteLine("Rectangle#1 " + objRect1);
        Console.WriteLine("Rectangle#2 " + objRect2);
        Console.WriteLine("Rectangle#3 " + objRect3);
        if (objRect1 == objRect2)
        {
            Console.WriteLine("Rectangle1 & Rectangle2 are Equal.");
        }
        else
        {
            if (objRect1 > objRect2)
            {
                Console.WriteLine("Rectangle1 is greater than Rectangle2");
            }
            else
            {
                Console.WriteLine("Rectangle1 is lesser than Rectangle2");
            }
        }
        if (objRect1 == objRect3)
        {
            Console.WriteLine("Rectangle1 & Rectangle3 are Equal.");
        }
        else
        {
            Console.WriteLine("Rectangle1 & Rectangle3 are not Equal.");
        }
     
    }



class Rectangle
{
    private int iHeight;
    private int iWidth;
    public Rectangle()
    {
        Height = 0;
        Width = 0;
    }
    public Rectangle(int w, int h)
    {
        Width = w;
        Height = h;
    }
    public int Width
    {
        get
        {
            return iWidth;
        }
        set
        {
            iWidth = value;
        }
    }
    public int Height
    {
        get
        {
            return iHeight;
        }
        set
        {
            iHeight = value;
        }
    }
    public int Area
    {
        get
        {
            return Height * Width;
        }
    }
    /* OverLoading == */
    public static bool operator ==(Rectangle a, Rectangle b)
    {
        return ((a.Height == b.Height) && (a.Width == b.Width));
    }
    /* OverLoading != */
    public static bool operator !=(Rectangle a, Rectangle b)
    {
        return !(a == b);
    }
    /* Overloding > */
    public static bool operator >(Rectangle a, Rectangle b)
    {
        return a.Area > b.Area;
    }
    /* Overloading < */
    public static bool operator <(Rectangle a, Rectangle b)
    {
        return !(a > b);
    }
    /* Overloading >= */
    public static bool operator >=(Rectangle a, Rectangle b)
    {
        return (a > b) || (a == b);
    }
    /* Overloading <= */
    public static bool operator <=(Rectangle a, Rectangle b)
    {
        return (a < b) || (a == b);
    }
    public override String ToString()
    {
        return "Height=" + Height + ",Width=" + Width;
    }
}

Monday, January 21, 2013

Get All the TABLES with Number of Rows and Columns

SELECT OBJECT_NAME(D.object_id) As [TABLE NAME], 
  SUM(row_count) [ROWS COUNT] , 
  Count(C.Column_Id) [COLUMN COUNT]
FROM sys.dm_db_partition_stats As D Inner JOIN sys.objects As o
  On o.object_id = D.object_id And o.type = 'u'
  Inner Join sys.columns As C On C.object_id = D.object_id
WHERE [index_id] IN (0,1)
GROUP BY D.object_id

Sunday, December 9, 2012

Check if Checkbox is checked using jQuery


to find out if checkbox is checked or not using jQuery. I was knowing one way to find out but there are couple of other ways as well to find out if checkbox is checked using jQuery. In this post, you will find all different possible ways.

1. First Way:

Below single line of code will provide the status of checkbox using jQuery. It checks whether the checked is checked or not using jQuery and will return 1 or 0.

1var isChecked = $('#chkSelect').attr('checked')?true:false;
I have noticed that on many website it is written that 'checked' attribute will return true or false, but this is not correct. If the checked box is checked then it return status as "checked", otherwise "undefined".

2. Second Way
1var isChecked = $('#chkSelect:checked').val()?true:false;

3. Third Way
1var isChecked = $('#chkSelect').is(':checked');
The above method uses "is" selector and it returns true and false based on checkbox status.

4. Fourth Way

The below code is to find out all the checkbox checked through out the page.
1$("input[type='checkbox']:checked").each(
2    function() {
3       // Your code goes here...
4    }
5);
Feel free to contact me for any help related to jQuery, I will gladly help you.

Find Current Location of Data and Log File of All the Database and get size of databases

Some time for carring data from one machine to another machine we need to copy database file

for that we need to copy database ldf and mdf file becaues this is eassiest way yo carring database. for this  we must be know the these db files are where is located on server so we can copy this.

First way to write this query on our Query window

SELECT name, physical_name AS current_file_location
FROM sys.master_files

Second way to find the location with Appropriate database file size 

SELECT DB_NAME(mf.database_id) AS databaseName
,mf.physical_name
,num_of_reads
,num_of_bytes_read
,io_stall_read_ms
,num_of_writes
,num_of_bytes_written
,io_stall_write_ms
,io_stall
,size_on_disk_bytes
FROM sys.dm_io_virtual_file_stats(NULL, NULL) AS divfs
JOIN sys.master_files AS mf ON mf.database_id = divfs.database_id
AND mf.file_id = divfs.file_id
ORDER BY 3 DESC 

Third way to find database details with size in shortest form that you wanted to find

SELECT
DB_NAME(mf.database_id) AS databaseName,
name as File_LogicalName,
case
when type_desc = 'LOG' then 'Log File'
when type_desc = 'ROWS' then 'Data File'
Else type_desc
end as File_type_desc
,mf.physical_name
,num_of_reads
,num_of_bytes_read
,io_stall_read_ms
,num_of_writes
,num_of_bytes_written
,io_stall_write_ms
,io_stall
,size_on_disk_bytes
,size_on_disk_bytes/ 1024 as size_on_disk_KB
,size_on_disk_bytes/ 1024 / 1024 as size_on_disk_MB
,size_on_disk_bytes/ 1024 / 1024 / 1024 as size_on_disk_GB

FROM sys.dm_io_virtual_file_stats(NULL, NULL) AS divfs
JOIN sys.master_files AS mf ON mf.database_id = divfs.database_id
AND mf.file_id = divfs.file_id
ORDER BY num_of_Reads DESC