Showing posts with label DBMS. Show all posts
Showing posts with label DBMS. Show all posts

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.

Database Management System Ebooks

Thursday, September 8, 2011

DBMS -Normalization

DBMS -Normalization

In the design of a relational database management system (RDBMS), the process of organizing data to minimize redundancy is called Normalization. 
The goal of database normalization is decompose relations with anomalies in order to produce smaller, well-structured relations.  Normalization usually involves dividing large tables into smaller
(and less redundant) tables and defining relationships between them. The objective is to isolate data so that additions, deletions, and
modifications of a field can be made in just one table and then propagated through the rest of the database via the defined relationship.Normalization didn't any headache who is the primary key of the relation.But if there is key then problem is occurs and normalization is needed.