on Leave a Comment

Functional Dependeny in DBMS

Functional dependency in DBMS is a constraint between two set of attributes. In a relational database schema having n attributes, there exists a universal relation R = {A1, A2, A3, ..., An}. A functional dependency is denoted by X→Y, where X and Y are subset of R. In relation R, attribute (or set of attributes) Y is functionally dependent to attribute X, means value of X can uniquely determine the value of Y.

The abbreviation of functional dependency is FD or f.d.
The left hand side is called determinant and right hand side is dependent.

Consider the below relation, in this each value of X uniquely determines value of Y


Now consider the below table, here there are two 1s in X attribute but both determines two different value of Y, this violates functional dependency X->Y.



Inference Rules for Functional Dependencies

In a database schema, F is a set of functional dependency. But are some other dependency that can be inferred or deduced from functional dependencies FD in F. 

The set of all dependencies including F as well as other dependencies inferred from F are known as closure of F and it is denoted by F*

For example: {Emp_id → {Emp_name, Emp_salary, Emp_mobile}}

Emp_mobile → {Emp_name, Emp_salary}

Following dependencies can be inferred from above two FD

Emp_mobile → Emp_name
Emp_id → Emp_id  

The following rules are inference rules for functional dependency.  

- Reflexive rule 

If Y ⊆ X, then X →Y

- Augmentation rule

If {X →Y},  then  XZ →YZ

- Transitive rule

If  {X →Y, Y →Z}, then X →Z

- Decomposition, or projective, rule

If {X →YZ}, then X →Y

- Union, or additive, rule

If {X →Y, X →Z}, then X →YZ 

- Pseudotransitive rule

If {X →Y, WY →Z}, then WX →Z




on Leave a Comment

Data Redundancy in DBMS with example

Data redundancy means redundant copies of data within database. Data redundancy leads to data inconsistency which will cause overall database performance. To avoid redundancy problem in database design Normalization is used. 

Opensource DBMS mysql provides some ways to avoid redundancy such as joins.

Example of data redundancy in DBMS

Data redundancy in DBMS

In the above table, Dep_id and Dep_manager_name is copied into multiple tuples . For example, Dep_id 22 is placed two times in table. If we need to update Dep_manager_name for Dep_id 22, then we have to update all records having Dep_id 22. If Dep_id 22 is placed with thousand records, then we need to update thousand record for small change and this results to increase in computational time.

Disadvantages of data redundancy in DBMS

Insertion anomaly

If there is one more Dep_id, let say 21 and currentlty no employee is working in this department. Then there will be no entry related to this Dep_id in table. Such a situation is known as insertion anomaly.

Deletion anomaly

In the above table, if record Emp_code 3 is deleted, then there will no record related to Dep_id 17. This will cause losing information about Dep_id 17.   

Updation anomaly

If we need to change Dep_manager name, then we have to update to record having same Dep_id. This will increase computation time.


Advantages of data redundancy in RDBMS

But sometimes, data redundancy is solution when you have unlimited storage and your basic need is faster access of data. When we store data in multiple tables for example student information in STUDENT table and student courses in another table STUDENT_COURSE and we need to access complete student data in one query, then joins is solution. But when data is large enough, joins decrease performance. There are many other solutions for faster join operation like indexing and other database constraint. But if data is large and joins are not working well, then data redundancy is also a solution.  



on 1 comment

Get Video Information PHP | Embed/Embed Package

PHP embed/embed package can used used for fetching video information such as duration , thumbnail and many other useful information.

First install the package via composer 

composer require embed/embed 

Then, include autoloader.php in source file and fetch video information as follows.

<?php

include "../Embed/src/autoloader.php";

use Embed\Embed;

$vidDetail =  getVideoDetail("<your video url>"); //it can be embed link also

function getVideoDetail($url){
    //Load any url:
   $info = Embed::create($url);
   $duration = "";
   foreach ($info->getProviders() as $providerName => $provider){
   foreach($provider->getBag()->getAll() as $prKey=>$prVal){
   if($prKey == duration){
   $duration = $prVal;
   continue;
   }
   }
   if($duration) continue;
   }
   if(strpos($url, "youtube.com")){
    $duration = str_replace("PT", "", $duration);
    $duration = str_replace("S", "", $duration);
    $durationArr = explode("M", $duration);
            $duration = $durationArr[0] * 60 + $durationArr[1] - 1;
   }
   $thumbnail = $info->image;
   return array("thumbnail" => $thumbnail, "duration" => $duration);
}

?>


on 1 comment

JavaScript Program to Display Hello World

In JavaScript, you can display any string using alert box. JavaScript alert is a method of window object. But we can also it explicitly without reference to window object. There are many other ways in JavaScript to display string like console.log method.

JavaScript Program to Display Hello World using Alert Box

<!doctype html>
<html>
  <head>
      <meta charset="utf-8">
      <title>Hello World</title>
  </head>
  <body>
      <button onclick="print()">Click Me...</button>
  </body>
  <script>
      function print(){
          alert("Hello World...");
      }
  </script>
</html>

Output:



When you click on this button, a pop up box occurs that displaying "Hello World...".

JavaScript Program to Display Hello World using console.log

console.log method is used to print string on console window. If you use this method nothing will display on the screen, but it will display on console window.

<!doctype html>
<html>
  <head>
      <meta charset="utf-8">
      <title>Hello World</title>
  </head>
  <body>
      <button onclick="print()">Click Me...</button>
  </body>
  <script>
      function disp(){
          console.log("Hello World...");
      }
  </script>
</html>

Output:







on Leave a Comment

JavaScript Variables

As other programming languages, JavaScript also supports data types and variables. Variables are piece of memory blocks in which we can store data (values). And data types decides what type of data can be stored in variables and what operations on variable can be performed.

JavaScript supports following data types:

Number, e.g. 100, 105.5, 10.0 etc.
String, e.g. 'abc', "xyz" etc.
Boolean, e.g. true and false 
Null and Undefined
Object (composite data type)

JavaScript represents numbers as 64-bit floating-point format defined by the IEEE 754 standard.

Example of JavaScript Variable

var keyword is used to declare variables in JavaScript

<script type="text/javascript">
      var a = 10;
      var b = 20;
      var c = a + b;
</script>

In above example, we define three variable using var keyword namely a, b and c. Variables a and b stores 10 and 20 respectively. And sum of a and b is assigned to variable c.

JavaScript Identifiers

All names are Identifiers. A variable must have unique name.

- Reserved words cannot be used as a variables name.
- Variables name should not start with a number like 0, 1, 2.
- Variable name should start with a alphabets or underscore like abc, _abc.
- All variable names are case sensitive.