Sunday, April 20, 2014

SQL - Structured Query Language


 
SQL


Structured Query Language and it also spell as Structured English Query Language (SEQUEL). The Main features of SQL are
  •  SQL stands for structured Query language
  •   SQL lets you access and manipulate databases
  •   SQL is an ANSI (American National Standards Institute) Standard
  •   SQL is a standard interactive and programming language for querying and modifying data and managing databases
  •   SQL can execute queries against the database 
  •   SQL ca set permissions on tables, procedures and views
  •   SQL can create stored procedures in a database
  •   The basis of SQL is RDBMS, it stands for Relational Database Management System
  •  The data in RDBMS is stored in database objects called tables and tables is nothing a collection of related data entries which is present in columns and rows





The following SQL statement will select all the records in the Customers Table

SELECT * FROM CUSTOMERS

(SQL is not case sensitive)

SQL is divided into two parts:

(1) The Data Manipulation Language (DML)
(2) The Data Definition Language (DDL)



The Main DML statements are given below
(1) SELECT
(2) UPDATE
(3) DELETE
(4) INSERT INTO
(5) SELECT INTO
The DDL part of SQL permits database tables to be created or deleted. It also defines indexes (keys), specified links between tables, and imposes constraints between tables. 

The most important DDL statements are given below
(1) Create Database
(2) Alter Database
(3) Create Table
(4) Alter Table
(5) Create INDEX
(6) Drop Index
(7) Drop table
(8) Drop Database


-----------------------------------------------------------------------------------------------------

SQL Select Statement

SELECT statement is used to select data from a database
The result is stored in a result table, called result-set
Syntax of the SQL Select Statement is

SELECT COLUMN_NAME FROM TABLE_NAME

for example.,

(1) SELECT * FROM CUSTOMERS: Selecting complete list of records and columns



CUST_ID CUST_NAME
CUST001 ASHWIN


(2) SELECT CUST_ID FROM CUSTOMERS: Selecting complete list of records with only cust_id column

CUST_ID
CUST001

 (3) SELECT DISTINCT PERSON_NAME FROM PERSONS

Persons Table is as follows


ID
PERSON_NAME
Address
City
Mobile
1
Sachin
10th Main Road
Mumbai
9845012345
2
Henry
11th Main Road
Bengaluru
9945012345
3
Sachin
8th Main Road
Mumbai
9845012345

Now ABOVE query will get you

PERSON_NAME
SACHIN
HENRY
  
In above table one of records is having duplicate values. If we need to display or extract only different values or the records, we can use "Select Distinct statement"

 

-----------------------------------------------------------------------------

 Creating Database

CREATE DATABASE <<DATABASE_NAME>>

If we want to create the database  of customers

CREATE DATABASE CUSTOMERS
 Now the DATABASE OF CUSTOMERS will be created....




Tuesday, October 15, 2013

//Author: Suresh Babu
//To find the biggest number in array (Single dimentional)

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

namespace ConsoleApplication15
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr1 = new int[5];
            for (int y = 0; y < arr1.Length; y++)
            {
                arr1[y] = int.Parse(Console.ReadLine());
            }
            int x = arr1.Max();
            Console.WriteLine("The biggest number of array is" + x);
        }
    }
}
           
                     
           

           
               
       


//Author: Suresh Babu
//Use of if and else to find the biggest of three numbers


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

namespace ConsoleApplication14
{
    class Program
    {
        static void Main(string[] args)
        {
            int x, y, z;
            x = int.Parse(Console.ReadLine());
            y = int.Parse(Console.ReadLine());
            z = int.Parse(Console.ReadLine());
            if (x > y && x > z)
            {
                Console.WriteLine("The value of x is {0} is greater than both y and z", x);
            }
            else if (y > x && y > z)
            {
                Console.WriteLine("The value of y is {0} is greater than both x and z", y);
            }
            else
            {
                Console.WriteLine("The value of z is {0} is greater than both x and y", z);
            }
               
        }
    }
}

Wednesday, July 24, 2013

Printing of characters of String in Reverse Order in C Sharp

//File Name: reverse
//Author: SURESH BABU
//Reference: Printing of characters of String in Reverse Order

using System;


namespace reverse
{
    class Program
    {
        static void Main(string[] args)
        {
            string name = "SURESH BABU";
            string reverse = "";
            foreach (char ch in name)
            {
                reverse = ch +reverse;
            }
            Console.WriteLine(reverse);
        }
    }
}

Example for Copy Constructor in C Sharp

Example for copy Constructor:

//Fileno: demo_49
//Author: SURESH BABU
//Reference: Copy Constructor

using System;


namespace demo_49
{
    public class CopyConstruct
    {
        private int x, y;
        public CopyConstruct(int a, int b)
        {
            x=a;
            y=b;
        }
        public  CopyConstruct(CopyConstruct T)
        {
           x=   T.x;
           y =  T.y;
        }
        public void show()
        {
            Console.WriteLine("The value of x and y are {0} and {1}",x,y);
        }
        public void print()
        {
            Console.WriteLine("The value of a and b are {0} and {1}",x,y);
        }


    }
    class Program
    {
        static void Main(string[] args)
        {
            CopyConstruct t3 = new CopyConstruct(80,90);
           
            CopyConstruct t2 = new CopyConstruct(t3);
            t2.show();
            t2.print();
           

        }
    }
}

Monday, July 22, 2013

Copying of Array1 to Array2 in C Sharp

Example to copy the Array1 to Array2 and print the details in C Sharp

//file name: demo_40
//Author: SURESH BABU
//Reference: Copying of array from another array

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

namespace demo_40
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] arr1 = new int[3, 3];
            int[,] arr2 = new int[3, 3];
            int i, j;

            // Storing User input in the Array

            for (i = 0; i < 3; i++)
            {
                for (j = 0; j < 3; j++)
                {
                    Console.WriteLine("Enter the Array Value:\t");
                    arr1[i, j] = Convert.ToInt32(Console.ReadLine());
                }
            }
            for (i = 0; i < 3; i++)
            {
                for (j = 0; j < 3; j++)
                {
                    arr2[i, j] = arr1[i, j];
                }
            }
            Console.Write("Elements of the Array2 = {");
            for (i = 0; i < 3; i++)
            {
             
                for (j = 0; j < 3; j++)
                {
                    Console.Write(" {0}", arr2[i, j]);
                }
            }
            Console.Write(" }");
            Console.ReadLine();
        }
    }
}

Jagged Arrays

In C Sharp: Jagged Arrays are described as it is collection of arrays of different or same number of elements in it but of similar type only.

Syntax of the Jagged Array
---------------------------

int[ ][ ] <<Jagged Array variable Name>  =  new int [ 2 ][ ];

int[ ][ ] jagged_array  =  new int [ 2 ][ ];

In above syntax, jagged_array is variable of Array data type, where it is having 2 Arrays in it.

Example:

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

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

            //Declare two elements of the Array

            int[][] array = new int[2][];

            //filling the elements
            array[0] = new int[5] { 1, 3, 5, 7, 9 };
            array[1] = new int[4] { 2, 4, 6, 8 };

            //Display the array elements

            for (int i = 0; i < array.Length; i++)
            {
                Console.Write("Element of Array [{0}]: ", i);
                for (int j = 0; j < array[i].Length; j++)
                {
                    Console.Write("{0}{1}", array[i][j], j == (array[i].Length - 1) ? "" : "",i,j);
                }
                Console.WriteLine();
            }    

        }
    }
}