September 29

Difference between Primary Key & Foreign Key

Primary Key

Primary key uniquely identify a record in the table.

Primary Key can’t accept null values.

By default, Primary key is clustered index and data in the database table is physically organized in the sequence of clustered index.

We can have only one Primary key in a table.

 

Foreign Key

Foreign key is a field in the table that is primary key in another table.

Foreign key can accept multiple null value.

Foreign key do not automatically create an index, clustered or non-clustered. You can manually create an index on foreign key.

We can have more than one foreign key in a table.

Category: MySQL | LEAVE A COMMENT
September 25

What is an index?

It is a data structure  that stores the values for a specific column in a table. An index is created on a column of a table. So, the key points to remember are that an index consists of column values from one table, and that those values are stored in a data structure. The index is a data structure – remember that.

What kind of data structure is an index?

B- trees are the most commonly used data structures for indexes. The reason B- trees are the most popular data structure for indexes is due to the fact that they are time efficient – because look-ups, deletions, and insertions can all be done in logarithmic time. And, another major reason B- trees are more commonly used is because the data that is stored inside the B- tree can be sorted.

ecause an index is basically a data structure that is used to store column values, looking up those values becomes much faster. And, if an index is using the most commonly used data structure type – a B- tree – then the data structure is alsosorted. Having the column values be sorted can be a major performance enhancement – read on to find out why.

Let’s say that we create a B- tree index on the Employee_Name column This means that when we search for employees named “Jesus” using the SQL we showed earlier, then the entire Employee table does not have to be searched to find employees named “Jesus”. Instead, the database will use the index to find employees named Jesus, because the index will presumably be sorted alphabetically by the Employee’s name. And, because it is sorted, it means searching for a name is a lot faster because all names starting with a “J” will be right next to each other in the index! It’s also important to note that the index also stores pointers to the table row so that other column values can be retrieved – read on for more details on that.

September 18

Difference between array_merge and array_combine in php

array_merge

Merge one or more arrays.

Merges the elements of one or more arrays together so that the values of one are appended to the end of the previous one.
If the input arrays have the same string keys, then the later value for that key will overwrite the previous one or if the arrays contain numeric keys, then the later value will not overwrite the original value and will be appended.

Values in the input array with numeric keys will be renumbered with increment keys starting from zero in the result array.

Kindly have a look on example given below

Example:
<?php
$array1 = array(“color” => “green”, 2, 4);
$array2 = array(“a”, “b”, “color” => “blue”, “shape” => “sqaure”, 4);
$result = array_merge($array1, $array2);
print_r($result);
?>

 

Output will:

Continue reading

Category: Arrays | LEAVE A COMMENT
September 16

MYSQL: JOINS

MySQL JOINS are used to retrieve data from multiple tables. A MySQL JOIN is performed whenever two or more tables are joined in a SQL statement.

Three types of joines:

 

1. Inner join
2. Left join
3. Right join

 

INNER JOIN

If you’ve already written a statement that uses a MySQL INNER JOIN. It is the most common type of join. MySQL INNER JOINS return all rows from multiple tables where the join condition is met.

Syntax

The syntax for the MySQL INNER JOIN is:
SELECT columns
FROM table1
INNER JOIN table2
ON table1.column = table2.column;

Continue reading

Category: MySQL | LEAVE A COMMENT