-->

Saturday, March 1, 2014

How to Rename or Drop User-Defined Database in SQL Programming

Renaming a User-Defined Database

After creating a user-defined database in SQL server, programmer can rename a database whenever required. Only a system administrator or the database owner can rename a database. The sp_renamedb stored procedure is used to rename a database. The syntax of the sp_renamedb statement is:

Sp_renamedb old_database_name, new_database_name
Where

  • old_database_name is the current name of the database
  • new_database_name is the new name of the database 
For example, the following SQL query renames the Personnel database.
Sp_renamedb Personnel Personnel1

Dropping a User-Defined Database

Programmer can delete a database when it is no longer required. This causes all the database files and data to be deleted. Only the users with sysadmin role and the database owner have the permissions to delete a database. The syntax of the DROP DATABASE statement is:

DROP DATABASE database_name
Where
Database_name is the name of the database.

The following SQL query deletes the Employee database:
DROP DATABASE Employee

Programmer cannot delete a system-defined database. Programmer can rename or delete a database using the Object Explorer window by right-clicking the Databases folder and selecting the Rename or Delete option from the shortcut menu.
Create User-Defined Database 

Merging the ordered Singly Linked Lists in 'C'

The merging is over. The merged list can be traversed with the help of the external pointer ROOT. ROOT points to the node with information 1. Node with information 1 points to the node with information 10. Next node is the node with information 20. Similarly the nodes with information 23 and 25 are the next node. The node with information 25 is the last node of the merged list.

Algorithm to merge two ordered linked lists:

MERGEOLLS(ROOT1,ROOT2)
IfROOT-->INFO<ROOT2-->INFO Then:
  ROOT<--ROOT1;  ROOT1<--ROOT1-->LINK
Else:
  ROOT<--ROOT2;  ROOT2<--ROOT2-->LINK
[End of If]
PTR<--ROOT
Repeat While ROOT1< >NULL AND ROOT2< >NULL
  If ROOT1-->INFO<ROOT2-->INFO Then:
      PTR-->LINK<--ROOT1
      PTR<--PTR-->LINK
 Else:
      PTR-->LINK<--ROOT2
      PTR<--PTR-->LINK
      ROOT2<--ROOT2-->LINK
  [End of If]
[End of While]
If ROOT1 = NULL Then:
  PTR<--ROOT2
[End of If]
If ROOT2 = NULL Then:
   PTR<--ROOT1
[End of If]
Exit.

Increment operator in c# programming

Those operator, which is used for increment by one in any value known as increment operator. These are two types.

  1. Pre-increment operator
  2. Post-increment operator 
In pre-increment operator appear before its operand, such as ++a. Here "a" is a operand and ++ is the increment operator. In this case, value of the operand(a) will be incremented by one "after" it has been incremented.

In post-increment operator appear after its operand, such as a++. Similarly again, "a" is a operand and ++ is the increment operator.In this case, value of the operand(a) will be incremented by one "before" it has been incremented.

Lets take an simple example of both pre and post increment
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            double a;
            a = 1.5;
            Console.WriteLine(++a);
            a = 1.5;
            Console.WriteLine(a++);
            Console.WriteLine(a);

            Console.ReadKey();

        }    

    }

}

Code generate the following output

Increment operator in c# programming

In this example, variable a hold 1.5 double number. When compiler compile third line of statement, which is 
Console.WriteLine(++a). Pre-increment the value by one according to above definition. In forth line of statement again variable a replace with 1.5 double number. According to post-increment, first print same value of variable a (according to line-5) that is 1.5 , after that value has been incremented by one (according to line-6) that is 2.5.

Increment operators in expression

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            int a = 7;
            Console.WriteLine(++a * a++ + a++ * ++a);
            Console.ReadKey();

        }      

    }
}

Code generate the following output

Increment operator in c# programming
In this example, compiler first check operator precedence, here multiply sign take high precedence than addition sign. Also expression evaluate left to right, so first variable a is pre-incremented (value of a=8) also multiply with post-increment variable( a=8). So the result of first half is 64. In the next half, the value of variable a is post-incremented ( value of a=9) also multiply with pre-incremented (a=11 according to above definition). So the result of second half is 99. Now add both result, 64+99 is 163.

Friday, February 28, 2014

Decrement operator in c# programming

Those operator, which is used for decrement by one in any value known as decrement operator. These are two types.

  1. Pre-Decrement operator
  2. Post-Decrement operator 

In pre-decrement operator appear before its operand, such as --a. Here "a" is a operand and -- is the decrement operator. In this case, value of the operand(a) will be decremented by one "after" it has been decremented.

In post-decrement operator appear after its operand, such as a--. Similarly again, "a" is a operand and -- is the decrement operator.In this case, value of the operand(a) will be decremented by one "before" it has been decremented.
Lets take an simple example of both pre and post decrement
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            double a;
            a = 1.5;
            Console.WriteLine(--a);
            a = 1.5;
            Console.WriteLine(a--);
            Console.WriteLine(a);

            Console.ReadKey();

        }      

    }
}

Code generate the following output

Decrement operator in c# programming

In this example, variable a hold 1.5 double number. When compiler compile third line of statement, which is 
Console.WriteLine(--a). Pre-decrement the value by one according to above definition. In forth line of statement again variable a replace with 1.5 double number. According to post-decrement, first print same value of variable a (according to line-5) that is 1.5 , after that value has been decremented by one (according to line-6) that is 0.5.

Decrement operators in expression

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            int a = 7;
            Console.WriteLine(--a * a--+a--*--a);            
            Console.ReadKey();

        }      

    }
}

Code generate the following output

Decrement operator in c# programming
In this example, compiler first check operator precedence, here multiply sign take high precedence than addition sign. Also expression evaluate left to right, so first variable a is pre-decrement (value of a=6) also multiply with post-decrement variable( a=6). So the result of first half is 36. In the next half, the value of variable a is post-decremented ( value of a=5) also multiply with pre-decrement (a=3 according to above definition). So the result of second half is 15. Now add both result, 36+15 is 51.

Merging the ordered Singly Linked List for Data Structure in 'C'

Merging the ordered Singly Linked List:

         Often it is necessary to merge two linked lists into a single linked list. Merging of two arrays consumes lots of time and storage whereas merging of two linked lists is simple. Just changing the address stored in link field of each node as and when required carries out the merging in case of linked list. Let us consider the example as follows before dealing with algorithm and program.



Both of the linked lists are in ascending order. First node address of each linked list is stored in ROOT1 and ROOT2 respectively. In order to merge these lists we can use another external pointer ‘ROOT’ to point to the first node of each list is compare. The node whose information is less become the first node of the merged list and the address of that node is stored in ‘ROOT’ .The process is continued till the end of each list.
In the above example the information of the first node of the second list is smaller than that of first node of the first linked list. So, ROOT is assigned with ROOT2 and ROOT2 is updated to point to the next node of the second linked list . Now ROOT2 points to a node with information 23.

Default selection RadiobuttonList Example in ASP.NET

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Default selection</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True" 
            onselectedindexchanged="RadioButtonList1_SelectedIndexChanged">
            <asp:ListItem>Literal Control</asp:ListItem>
            <asp:ListItem>Label Control </asp:ListItem>
            <asp:ListItem>Localize control</asp:ListItem>
            <asp:ListItem>Multiview Control</asp:ListItem>
        </asp:RadioButtonList><br />
        <asp:Label ID="Label1" runat="server"></asp:Label>

    </div>
    </form>
</body>
</html>

Code behind code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default5 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (RadioButtonList1.SelectedIndex < 0)
        {
            RadioButtonList1.SelectedIndex = 0;
            Label1.Text += "Default selection in radio button list.";
        }
        else
        {
            Label1.Text = "Your item selected are : " + RadioButtonList1.SelectedItem.Text;
        }  
    }
}

Code generate the following output

Default selection RadiobuttonList Example in ASP.NET

Thursday, February 27, 2014

C# Programming: How to find pow of given number

You can easily find power of given number using Pow, which is static method of Math class. Here we take an example with integer number. Also gives II method , which is performed by programming.

Both method include in single program

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 2, b = 4;   

            

            Console.WriteLine(" The power of given number is {0}",Math.Pow(a, b));
            // Second method
        int result= Fun(2, 6);
        Console.WriteLine(" The power of given number is {0}", result);
            Console.ReadKey();

        }

        private static int Fun(int a, int b)
        {
            if (b >= 1)
            {
                return (a * Fun(a, --b));
            }
            else
                return 1;
        }
      

    }
}

Code generate the following output

C# Programming: How to find pow of given number
© Copyright 2013 Computer Programming | All Right Reserved