Tuesday 19 January 2016

SQL

Introduction


What is SQL?

  • SQL stands for Structured Query Language
      you can access and manipulate(build) the database.


What Can SQL do?

SQL can execute queries against a database
SQL can retrieve data from a database
SQL can insert records in a database
SQL can update records in a database
SQL can delete records from a database
SQL can create new databases
SQL can create new tables in a database
SQL can create stored procedures in a database
SQL can create views in a database
SQL can set permissions on tables, procedures, and views




Database Tables

A database most often contains one or more tables. Each table is identified by a name (e.g. "Student" or "Employee"). Tables contain records (rows) with data.

>rows are also know as tuples.


 Student ID     Student name     contact     age
1                       Ash                    890          21
2                      Anny                  789           22
3                      Stain                   465           20
4                      Harry                  769            25
5                       Dev                    899            23


Some of The Most Important SQL Commands

SELECT - extracts data from a database
UPDATE - updates data in a database
DELETE - deletes data from a database
INSERT INTO - inserts new data into a database
CREATE DATABASE - creates a new database
ALTER DATABASE - modifies a database
CREATE TABLE - creates a new table
ALTER TABLE - modifies a table
DROP TABLE - deletes a table
CREATE INDEX - creates an index
DROP INDEX - deletes an index





 

The SQL SELECT Statement :

The SELECT statement is used to select data from a database.

SQL SELECT Syntax
 
SELECT column_name,column_name
FROM table_name;

and
 
SELECT * FROM table_name;
 
Example:
 
 SELECT * FROM Student;
 

The SQL SELECT DISTINCT Statement

In a table, a column may contain many duplicate values; and sometimes you only want to list the different (distinct) values.
 
 SELECT DISTINCT column_name,column_name
FROM table_name;
 
 
Example:
select distinct Student name from Student ;


The SQL WHERE Clause 

The WHERE clause is used to extract only those records that specifies the needs .

SQL WHERE Syntax

SELECT column_name,column_name
FROM table_name
WHERE column_name operator value;
 
Example 
 
SELECT * FROM Student
WHERE name='Ash';
 

Operators in The WHERE Clause

The following operators can be used in the WHERE clause:
Operator   Description
=         Equal
<>         Not equal. 
>         Greater than
<         Less than
>=         Greater than or equal
<=         Less than or equal
BETWEEN         Between an inclusive range
LIKE         Search for a pattern
IN       To specify multiple possible values for a column
 
 
 
 

Monday 11 January 2016

Java script 7

Function Declarations

 function functionName(parameters)

 {
  code to be executed

Example

function myFunction(a, b)
 {
    return a + b;
}

Function Expressions

A function expression can be stored in a variable:

Example

var x = function (a, b) {return a + b}; 
 
 

Functions Can Be Used as Values

 

Example

function myFunction(a, b)
 {
    return a + b;
}

var x = myFunction(4, 3);
 

Function Parameters and Arguments

  

functionName(parameter1, parameter2, parameter3)

 {
    code to be executed
}  

Java script 6

JavaScript Form Validation

 

If the form submitted is Empty,the function should return alert message and prevent from submitting the form.

JavaScript Example

function validateForm()
 {
    var x = document.forms["myForm"]["fname"].value;
    if (x == null || x == " ")
 {
        alert("Name must be filled out");
        return false;
    }
}

 After filling out the fname the form will be submitted. 

 

Typical validation tasks are:
  • has the user filled in all required fields?
  • has the user entered a valid date?
  • has the user entered text in a numeric field?

End of the basic Java script.

Friday 8 January 2016

Java script 5

JavaScript Loops

 

  •  for

  • while

  •  do while 

    The for loop has the following syntax:

     
          for (statement 1; statement 2; statement 3)
          {
               code block to be executed
          }

 Example

for (i = 0; i < 5; i++) 
{
    text += "The number is " + i + "<br>";
}

The While Loop Syntax

while (condition
{
    code block to be executed
}

Example

In the following example, the code in the loop will run, over and over again, as long as a variable (i) is less than 5:

Example

while (i < 5
{
    text += "The number is " + i;
    i++;
}

The Do/While Loop Syntax

The do/while loop is a variant of the while loop.

do {
    code block to be executed
}
while (condition);

Example

The example below uses a do/while loop. The loop will always be executed at least once, even if the condition is false, because the code block is executed before the condition is tested:

Example

do {
    text += "The number is " + i;
    i++;
}
while (i < 10);


 

 

Java script 4

Conditional Statements 

JavaScript we have the following conditional statements:

  • if

  • else

  • else if 

  • switch 

     

    The if Statement

    Syntax

    if (condition
    {
        block of code to be executed if the condition is true
     
     Example : 
     <hmtl>
    <script>
    var age=20;
    if(age>18)
    {
    document.write("Qualifies for driving");
    }
    </scritp>
    </html>

    The else Statement

    if (condition)
     {
        block of code to be executed if the condition is true
    else
     {
        block of code to be executed if the condition is false
    }
     
    Example : 
     <hmtl>
    <script>
    var age=20;
    if(age>18)
    {
    document.write("Qualifies for driving");
    else
    {
    document.write("doesnt qulify for driving");
    }
    </scritp>
    </html>

    The else if Statement

    Use the else if statement to specify a new condition if the first condition is false.

    Syntax

    if (condition1
    {
        block of code to be executed if condition1 is true
    }
     else if (condition2
    {
        block of code to be executed if the condition1 is false and condition2 is true
    }
     else
     {
        block of code to be executed if the condition1 is false and condition2 is false
    }
     
     
    Example:Simillar to if else.

    The JavaScript Switch Statement

     
    Syntax 
     
     switch(expression)
     {
        case n:
            code block
            break;
        case n:
            code block
            break;
        default:
            default code block
    }
     
     

Wednesday 6 January 2016

Java script 3

JavaScript Arithmetic Operators

Operator Description
 +                  Addition
 -                 Subtraction
 *                 Multiplication
 /                 Division
 %                 Modulus
 ++                 Increment
 --                 Decrement

 

JavaScript Assignment Operators

Operator Example
=                  x = y
+=                  x += y
-=                  x -= y
*=                  x *= y
/=                  x /= y
%=                 x %= y

 

JavaScript  Logical Operators

OperatorDescription
= =                            equal to
= = =                              equal value and equal type
!=                            not equal
!==                            not equal value or not equal type
>                            greater than
<                            less than
>=                            greater than or equal to
<=                            less than or equal to
?                             ternary operator

 

JavaScript Function Syntax

 function name(parameter1, parameter2, parameter3)

 {
    code to be executed

 

 Example:

var x = myFunction(5, 2);        // Function is called, return value will end up in x
function myFunction(a, b)

 {
    return a * b;                // Function returns the product of a and b }

 






















































































































 
































































Sunday 3 January 2016

Java script 2

JavaScript Syntax


Java script statements  are separated by semicolons (;)

Ex:

var x = 2; var y = 3; var z = x + y; 

the values (fixed) are also known as literals are written directly instead of putting them in a qoutes

20.2

03

string are written as

"Google"

"Blackfacers"

 

Variables can be assigned values using = operator :

var x;

x=50;

Arithmetic operators :
 

(5*2)+5

 The values can be of string type can also be joined using operator + like

"Black" + "  " + "facers"

Blackfacers will be the output.


Java script comments :

Code after double slashes  //  or between      /*  and  */     is treated as a comment.

  Javascript program ex:

 var x = 10;
var y =5;
var z = x + y;
document.getElementById("sample").innerHTML = z;

JavaScript Code Blocks :

JavaScript statements can be grouped together in code blocks, inside curly brackets {...}.

 function myFunction()
{
    document.getElementById("demo").innerHTML = "Hello CODERS.";
    document.getElementById("sample").innerHTML = "How are you?";
}

Here function is a keyword.