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

Thursday, 6 June 2013

Basic concept of Static SQL and Dynamic SQL

Static SQL:

Static SQL is the type of SQL in which we cannot change the form of SQL statements unless we change our program. The output of our program will be similar each time based upon the input value. If we use static SQL statements of UPDATE a table, then the table will be updated every time we enter new data. We cannot expect other operations from the program unless we change the whole SQL statements to make them do so.

However, the static SQL can be made flexible to some extent by using so called host variables.

This model can be useful in developing programs that are used to do same tasks time and again, like keeping record of items sold in a store (a billing system).

Dynamic SQL:

Basically, a Dynamic SQL program generates SQL statements or can take SQL statements as input, in form of string, in order to provide flexibility to the program. That is why, it can be considered to be more interactive than Static SQL. In a deeper sense, it is capable of translating the user input into an executable SQL statement. The input is capable of changing the operation performed by the program.

However, there are some statements in SQL that cannot be used dynamically.

This model is useful in programs in which we might need to use multiple kinds of operations on the same data. It is also used in such cases where we may need to use many Static SQL statements, which might prove tedious and lengthy job.  Thus, dynamic SQL provides better flexibility but still due to its complexity, it is slower than Static SQL while execution. 

Saturday, 1 June 2013

Inner Join, Outer Join and Union

Inner Join: Inner join is a way of combining two relations by matching a tuple of a relation with corresponding tuple in next relation, only when they have a common value in a particular attribute.

Outer Join: Outer join is a way of combining two relations by matching a tuple of a relation with corresponding tuple in next relation, but it also includes tuples which have no match in other relation. The tuple which exist on only one relation take null value in remaining attributes. An outer join is either a left-outer join or a right-outer join based on whether all items are taken from relation on left or relation on right respectively.

Union: Union is a way of combining two relations by taking all the elements of both relations.  

Take the following example:

Relation A:
Name
Age
Randy
16
Nathan
12
Sunny
15

Relation B:
Name
Grade
Randy
11
Nathan
7
Yogi
10
Rachel
8

Union of A and B:
Name
Age
Name
Grade
Randy
16
Randy
11
Nathan
12
Nathan
7
Sunny
15
Sunny
null
Yogi
null
Yogi
10
Rachel
null
Rachel
8
*union has all elements from both relations.

Inner Join:
Name
Age
Name
Grade
Randy
16
Randy
11
Nathan
12
Nathan
7
*inner join has only elements which can be matched from A to B.

Outer Join:
Name
Age
Name
Grade
Randy
16
Randy
11
Nathan
12
Nathan
7
Yogi
null
Yogi
10
Rachel
null
Rachel
8

*it has even elements which are not in A and this outer join is specifically a right outer join as it includes all items from relation B which we assume to be on the right.