Sunday, September 25, 2011

SQL Tutorial Part4

SQL – Operators

What is an Operator in SQL?

An operator is a reserved word or a character used primarily in an SQL statement's WHERE clause to perform operation(s), such as comparisons and arithmetic operations. Operators are used to specify conditions in an SQL statement and to serve as conjunctions for multiple conditions in a statement.

       Arithmetic operators
       Comparison operators
       Logical operators
       Operators used to negate conditions


SQL Arithmetic Operators:

Assume variable a holds 10 and variable b holds 20 then:

Show Examples
Operator                   Description                                    Example

+            Addition - Adds values on either side of       a + b will give 30
             the operator

-            Subtraction - Subtracts right hand                  a - b will give -10
             operand from left hand operand

*            Multiplication - Multiplies values on either    a * b will give 200
             side of the operator

/            Division - Divides left hand operand by         b / a will give 2
             right hand operand

%            Modulus - Divides left hand operand by     b % a will give 0
             right hand operand and returns
             remainder

SQL Comparison Operators:

Assume variable a holds 10 and variable b holds 20 then:

Show Examples

Operator              Description                                      Example

=            Checks if the value of two operands are        (a = b) is not true.
             equal or not, if yes then condition
             becomes true.

!=          Checks if the value of two operands are         (a != b) is true.
             equal or not, if values are not equal then
             condition becomes true.

<>          Checks if the value of two operands are        (a <> b) is true.
             equal or not, if values are not equal then
             condition becomes true.

>           Checks if the value of left operand is               (a > b) is not true.
             greater than the value of right operand,
             if yes then condition becomes true.

<            Checks if the value of left operand is less         (a < b) is true.
             than the value of right operand, if yes
             then condition becomes true.

>=          Checks if the value of left operand is               ( a >= b) is not true.
             greater than or equal to the value of
             right operand, if yes then condition
             becomes true.

<=          Checks if the value of left operand is less         (a <= b) is true.
             than or equal to the value of right
             operand, if yes then condition becomes
             true.

!<           Checks if the value of left operand is not          (a !< b) is false.
             less than the value of right operand, if
             yes then condition becomes true.

!>           Checks if the value of left operand is not           (a !> b) is true.
             greater than the value of right operand,
             if yes then condition becomes true.

SQL Logical Operators:

Here is a list of all the logical operators available in SQL.

Show Examples  
 Operator                                            Description

ALL                         The ALL operator is used to compare a value to all values in another
                                 valueset.

AND                       The AND operator allows the existence of multiple conditions in an SQL
                                statement's WHERE clause.

ANY                       The ANY operator is used to compare a value to any applicable value in
                                the list according to the condition. 
 
BETWEEN             The BETWEEN operator is used to search for values that are within a set
                                of  values, given the minimum value and the maximum value.

EXISTS                  The EXISTS operator is used to search for the presence of a row in a
                               specified table that meets certain criteria.

IN                           The IN operator is used to compare a value to a list of literal values that
                                have been specified.

LIKE                      The LIKE operator is used to compare a value to similar values using
                               wildcard operators.

NOT                       The NOT operator reverses the meaning of the logical operator with
                                which it is used. NOT EXISTS, NOT BETWEEN, NOT IN etc

OR                          The OR operator is used to combine multiple conditions in an SQL
                                 statement's WHERE clause.

IS NULL                The NULL operator is used to compare a value with a NULL value.

UNIQUE                The UNIQUE operator searches every row of a specified table for
                               uniqueness (  no duplicates).

SQL Tutorial Part3

SQL - Data Types

SQL data type is an attribute that specifies type of data of any object. Each column, variable and expression has related data type in SQL.

You would use these data types while creating your tables. You would choose a particular data type for a table column based on your requirement.

SQL Server offers six categories of data types for your use:

Exact Numeric Data Types:


    DATA TYPE           FROM                                                TO

bigint              -9,223,372,036,854,775,808             9,223,372,036,854,775,807

int                           -2,147,483,648                                    2,147,483,647

smallint                          -32,768                                          32,767

tinyint                                 0                                                 255

bit                                      0                                                      1

decimal                       -10^38 +1                                     10^38 .1

numeric                       -10^38 +1                                     10^38 .1

money               -922,337,203,685,477.5808              +922,337,203,685,477.5807

smallmoney          -214,748.3648                                      +214,748.3647

Approximate Numeric Data Types:
DATA TYPE           FROM                                     TO

float                  -1.79E + 308                           1.79E + 308

real                   -3.40E + 38                            3.40E + 38

Date and Time Data Types:

   DATA TYPE              FROM                                       TO

datetime                        Jan 1, 1753                                Dec 31, 9999

smalldatetime                Jan 1, 1900                                 Jun 6, 2079

date                     Stores a date like June 30, 1991

time                     Stores a time of day like 12:30 P.M.

SQL Tutorial Part2

. SQL Commands:

The   standard   SQL   commands     to  interact  with  relational  databases  are  CREATE, SELECT,
INSERT, UPDATE, DELETE, and DROP. These commands can be classified into groups based on
their nature:

DDL - Data Definition Language:  


Command                               Description

CREATE                           New table, a view of a table, or other object in database

ALTER                             Modifies an existing database object, such as a table.

DROP                               Deletes an entire table, a view of a table or other object in the
                                          database.


DML - Data Manipulation Language:

      Command                   Description

         INSERT                                         Creates a record

                         
         UPDATE                                         Modifies records

         DELETE                                          Deletes records

 

DCL - Data Control Language
Command                   Description

  GRANT                                Gives a privilege to user

  REVOKE                       Takes back privileges granted from user

 


DQL - Data Query Language:

      Command                    Description


      SELECT                 Retrieves certain records from one or more tables 

 
SQL –Syntax

SQL is followed by unique set of rules and guidelines called Syntax. This tutorial gives you a
quick start with SQL by listing all the basic SQL Syntax:

All the SQL statements start with any of the keywords like SELECT, INSERT, UPDATE, DELETE,
ALTER, DROP, CREATE, USE, SHOW and all the statements end with a semicolon (;).

Important point to be noted is that SQL is case insensitive which means SELECT and select have same meaning in SQL statements but MySQL make difference in table names. So if you are working with MySQL then you need to give table names as they exist in the database.

SQL SELECT Statement:

SELECT column1, column2....columnN
FROM     table_name;

SQL DISTINCT Clause:

SELECT DISTINCT column1, column2....columnN
FROM     table_name;

SQL WHERE Clause:

SELECT column1, column2....columnN
FROM     table_name
WHERE  CONDITION;

SQL AND/OR Clause:

SELECT column1, column2....columnN
FROM     table_name
WHERE  CONDITION-1 {AND|OR} CONDITION-2;

SQL IN Clause:

SELECT column1, column2....columnN
FROM     table_name
WHERE  column_name IN (val-1, val-2,...val-N);


SQL BETWEEN Clause:

SELECT column1, column2....columnN
FROM    table_name
WHERE   column_name BETWEEN val-1 AND val-2;

SQL Tutorial Part1

  
                                       SQL Tutorial 

SQL is a database computer language designed for the retrieval and management of data in relational database.

SQL stands for Structured Query Language. This tutorial gives an initial push to start you with SQL.

This SQL tutorial gives unique learning on Structured Query Language and it helps to make practice on SQL commands which provides immediate results. SQL is a language of database, it includes database creation, deletion, fetching rows and modifying rows etc.

SQL is an ANSI (American National Standards Institute) standard but there are many different versions of the SQL language.

What is SQL?

SQL is structured Query Language which is a computer language for storing, manipulating and retrieving data stored in relational database.

Operating system Short Question Part4


What are the different Dynamic Storage-Allocation methods? How to satisfy a request of size n from a list of free holes?
  • First-fit: Allocate the first hole that is big enough.
  • Best-fit: Allocate the smallest hole that is big enough; must search entire list, unless ordered by size. It produces the smallest leftover hole. 
  • Worst-fit: Allocate the largest hole; must also search entire list. Produces the argest left over hole. First-fit and best-fit are better than worst-fit in terms of speed and storage utilization.
 
What is fragmentation? Different types of fragmentation?
Fragmentation occurs in a dynamic memory allocation system when many of the free blocks are too small to satisfy any request. 
  • External Fragmentation: External Fragmentation happens when a dynamic memory allocation algorithm allocates some memory and a small piece is left over that cannot be effectively used. If too much external fragmentation occurs, the amount of usable memory is drastically reduced. Total memory space exists to satisfy a request, but it is not contiguous

  •  Internal Fragmentation: Internal fragmentation is the space wasted inside of allocated memory blocks because of restriction on the allowed sizes of allocated blocks. Allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used Reduce external fragmentation by compaction 
  •  Shuffle memory contents to place all free memory together in one largeblock. 
  • Compaction is possible only if relocation is dynamic, and is done at execution time.
  
Under what circumstances do page faults occur? Describe the actions taken by the operating system when a page fault occurs?
A page fault occurs when an access to a page that has not been brought into main memory takes place. The operating system verifies the memory access, aborting the program if it is invalid. If it is valid, a free frame is located and I/O is requested to read the needed page into the free frame. Upon completion of I/O, the process table and page table are updated and the instruction is restarted. When a process is executed with only few pages in memory and when an instruction is encountered which refers to any instruction or data in some other page, which is not present in the main memory, a page fault occurs.