Thursday, October 24, 2013

Functions

-----------------------------------------------------------------
Average

1. SELECT AVG(fee) FROM student;

2. SELECT id, name FROM student
WHERE fee>(SELECT AVG(fee) FROM student);
------------------------------------------------------
Count

1. SELECT COUNT(*) FROM student;


Primary Key

// How we can create a Primary Key

CREATE TABLE student3
(
rollno int NOT NULL PRIMARY KEY,
name varchar(255) NOT NULL,
class varchar(255)
)

INNER JOIN


-------------------------------------------------------------------------------
//Make database and table

-- Database: `inventory`

-- Table Name -  `orders`
--

CREATE TABLE IF NOT EXISTS `orders` (
  `order_id` int(11) NOT NULL,
  `customer_id` int(11) NOT NULL,
  `order_date` date NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `orders`
--

INSERT INTO `orders` (`order_id`, `customer_id`, `order_date`) VALUES
(1, 1, '2013-10-25'),
(2, 2, '2013-10-26'),
(3, 3, '2013-10-27'),
(4, 4, '2013-10-28'),
(5, 5, '2013-10-29'),
(6, 6, '2013-10-30'),
(7, 7, '2013-10-31');

--------------------------------------------------------------------------------

//Make database and table

-- Database  Name  -  : `inventory`
-- Table Name  -   `customers`
--

CREATE TABLE IF NOT EXISTS `customers` (
  `customer_id` int(11) NOT NULL,
  `customer_name` varchar(222) NOT NULL,
  `contact_name` varchar(222) NOT NULL,
  `country` varchar(222) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `customers`
--

INSERT INTO `customers` (`customer_id`, `customer_name`, `contact_name`, `country`) VALUES
(1, 'smile Mittal', 'smile', 'india'),
(2, 'honey jindal', 'honey', 'india'),
(7, 'neha', 'n', 'n'),
(8, 'vipin', 'v', 'v'),
(9, 'l', 'l', 'l'),
(10, 'p', 'p', 'p');

---------------------------------------------------------------------------------------------

Querry of mysql for INNER JOIN

SELECT orders.order_id, customers.customer_name, orders.order_date
FROM orders
INNER JOIN customers
ON orders.customer_id=customers.customer_id;

--------------------------------------------------------------------------------------------
Querry of mysql for LEFT JOIN

SELECT customers.customer_name, orders.order_id
FROM customers
LEFT JOIN orders ON customers.customer_id = orders.customer_id

ORDER BY customers.customer_name;

--------------------------------------------------------------------------------------------
Querry of mysql for RIGHT JOIN
SELECT customers.customer_name, orders.order_id
FROM customers
RIGHT JOIN orders ON customers.customer_id = orders.customer_id
ORDER BY customers.customer_name;

Wednesday, October 23, 2013

The best way to Create a Web page

// Make a file index.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Web Page</title>
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
</head>
<body>
<div class="main"> <!--Main Start-->

<div class="header"> <!--Header Start-->
<h1>Header</h1>
</div> <!--Header End-->

<div class="contentarea"> <!--Contentarea Start-->

<div class="leftside_contentarea">  <!--Leftside Content Area Start-->
<h1>Leftside Content Area</h1>
</div>  <!--leftside Content Area End-->

<div class="rightside_contentarea"> <!--Rightside Content Area Start-->
<h1>Rightside Content Area</h1
></div> <!--Rightside Content Area End-->

</div> <!--Contentarea End-->


<div class="footer"> <!--Footer Start-->
<h1>Footer</h1
></div> <!--Footer End-->

</div> <!--Main End-->
</body>
</html>


//Make a file css.php


* {
margin:0px;
padding:0px;
}
img {
border: 0px;
}
body {
background-color:#deddc2;
}
.main {
margin:0 auto;
height:960px;
width: 1060px;
background-color:#f2f2e9;
-moz-box-shadow: 0 0 20px #454545;
-webkit-box-shadow: 0 0 20px #454545;
box-shadow: 0 0 20px #454545;
}
.header {
height:168px;
background:#c52f38;
}
.contentarea {
height:590px;
background:#d2d3d5;
margin-top:10px;
}
.leftside_contentarea {
width:270px;
float:left;
height:590px;
background:#C03;
}
.rightside_contentarea {
height:590px;
float:right;
width:790px;
background:#030;
}
.footer {
height:170px;
width:1060px;
background:#FF0;
margin-top:10px;
float:left;
}

The Simplest way in which we can create Radio Buttons with Database in php

// Make a file config.php


<?php
error_reporting(0);
mysql_connect("localhost","root","");
mysql_select_db("dbmusic");
?>


//Make a file reg_data.php


<?php include("config.php");

$gender= $_POST['gender'];
$hobbies = implode(",",$_POST["hobbies"]);

$insert = mysql_query("insert into  radio_check(radio,checkbox) values('$gender','$hobbies')");\
if($insert)
{
header("location:index.php?msg=succ");
}
else
{
header("location:index.php?msg=error");
}
?>


// Make a file index.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Radio And CheckBox</title>
</head>

<body>
<h1 align="center">Radio & Check Box With Database</h1>


<form action="reg_data.php" method="post">
<table border="1" align="center"   >
<br /><br />

<tr>
<td colspan="2"  align="center" style="color:#000; background:#666"> Enter your information here </td>
</tr>


<tr>
<td>Gender</td>
<td>Male<input type="radio" name="gender" value="male" >
Female <input type="radio" name="gender" value="female">
</td>
</tr>

<tr>
<td>Hobbies:</td>
<td>
Cooking :
<input type="checkbox" name="hobbies[]" value="Cooking">
Dance:
<input type="checkbox" name="hobbies[]" value="Dance">
Magic:
<input type="checkbox" name="hobbies[]" value="Magic">
</td>
</tr>

<tr>
<td colspan="2" align="center"><input type="submit" value="Submit" style="background:#666; color:#000" ></td>
</tr>

</table>
</form>

</body>
</html>


<?php
if($_GET["msg"]=="error")
{
echo "<h2> Data Not Insert</h2>";
}

if($_GET["msg"]=="succ")
{
echo "<h3 align=center>Data Insert</h3>";
}
?>


// Make database


-- Database Name : `dbmusic`
--
-- Table Name :  `radio_check`
-- --------------------------------------------------------CREATE TABLE IF NOT EXISTS `radio_check` (
  `id` int(25) NOT NULL AUTO_INCREMENT,
  `radio` varchar(25) NOT NULL,
  `checkbox` varchar(25) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;


-- Dumping data for table `radio_check`


INSERT INTO `radio_check` (`id`, `radio`, `checkbox`) VALUES
(1, 'male', 'Cooking,Dance'),
(2, 'female', 'Cooking,Dance'),
(7, 'male', 'Cooking,Dance,Magic');



Sessions

// Make a file index.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
// begin the session
session_start();

// set the value of the session variable 'foo'
$_SESSION['username']='Mandeep Deol';
$_SESSION['Password']='Password';

// echo a little message to say it is done
echo 'Setting Value of Username & Password';
?>
</body>
</html>


// Make a file 2.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
// begin our session
session_start();

// echo the session variable
echo 'Username is '.$_SESSION['username']."<br>";
echo 'Password is '.$_SESSION['Password'];
?>
</body>
</html>


// Make a file distroy.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
// Begin the session
session_start();
                                                                                                                     
// Unset all of the session variables.
session_unset();

// Destroy the session.
session_destroy();
echo "Destroy Session Completely.";
?>
</body>
</html>

Paging

// How Paging can be done in PHP


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Paging</title>
</head>

<body>
<?php
error_reporting("E_ALL ^ E_NOTICES");
  define('MAX_REC_PER_PAGE', 28);
  
  
  // find out how many rows are in the table 
  //$select = mysql_query("SELECT COUNT(*) FROM tablename where id='1' ") or die("Count query error!");
  //list($total) = mysql_fetch_row($select);
  $total = 65;  // total number of item in database 
  $total_pages = ceil($total / 30);  // in this we get total number of pages..set 30 item in per page..result 65/30 = 3 page 
  $page = intval(@$_GET["page"]);  // intval() function is used to get the integer value of a variable. 
  if (0 == $page)
  {
  $page = 1; // if page is equal to 0 assign 1
  }  
  $start = 30 * ($page - 1); // start page number  
  $max = 30;   // number of items to show per page
  ?>







<table align="center">
  <tr>
  <td><font color="#000000">Page:</font></td>
  <?php
   for ($i = 1; $i <=$total_pages; $i++) // $i = 1 , total_page = 3 
  {
  $txt = $i; // assign value
  if ($page != $i) 
  $txt = "<a href=\"" . $_SERVER["PHP_SELF"] . "?page=$i\">$txt</a>"; //assign value to page...get from url
  ?>  
  <td align="center"><font color="#FF0000" > <?php echo $txt ?></font></td>
  <?php
  }
  ?>
  </tr>
  </table>


</body>
</html>

Tips on How we can construct Menus in our Web page

Tips on How we can construct Menus in our Web page

// Make a file Style.css


* {
margin:0px;
padding:0px;
}
.menu {
width:800px;
height:60px;
background-color:#2A1F00;
border-radius:7px;
margin:0px auto;
}
.menu ul {
list-style:none;
text-align:center
}
.menu ul li {
padding:20px 0 0 45px;
float:left;
}
.menu ul li a {
display:block;
text-decoration:none;
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
color:#FFF;
font-size:17px;
padding:1px 0px 1px 0px
}
.menu ul li a:hover {
text-decoration:none;
color:#f6157f;
}


// Make a file Index.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Menus</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>

<body>
<div class="menu">
<ul>

<li style="background-image:none"><a href="#">Home</a></li>
<li ><a href="#p">Songs</a></li>
<li ><a href="#">Videos</a></li>
<li > <a  href="#">Quotations</a></li>
<li > <a  href="#" >Wallpaper</a></li>
<li > <a   href="#">About us</a></li>
<li >  <a  href="#">Contact us</a></li>
</ul>
</div>

</body>
</html>

The best way we can Search data from Database in PHP

// Firstly Make a file searchdata.php



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search Result</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>

<body>


<h1 align="center">Search Result</h1>



<?php
error_reporting(0);

//Connect To Database
mysql_connect("localhost","root","");
mysql_select_db("college");


//Get Keyword From Text Box
$searchterm = $_POST['searchterm'];

//This is only displayed if they have submitted the form with keyword
if(!empty($searchterm))
{
//Now we search for our search term, in the field the user specified
$selecta=mysql_query("select * from student where name like '%".$searchterm."%' ");

//And we display the results
while($rowa=mysql_fetch_array($selecta))
{
?>
<b style="color:#F00; font-size:14px; ">College Name:</b>
            <a href="#" style="text-decoration:none">
            <b style="color:#0472fe; font-size:15px; "><?php echo $rowa['name']; ?></b></a>
            <br />
         
            <b style="color:#F00; font-size:14px; ">Class:</b>
            <a href="#" style="text-decoration:none">
            <b style="color:#0472fe; font-size:15px; "><?php echo $rowa['class']; ?></b></a>
            <br />
         
            <b style="color:#F00; font-size:14px; ">rollno:</b>
            <a href="#" style="text-decoration:none">
            <b style="color:#0472fe; font-size:15px; "><?php echo $rowa['rollno']; ?></b></a>
            <br />
<?php
}
}
else
{
 //If they did not enter a search term we give them an error
echo "<h1 align=center>Please Enter a keyword to find! </h1>";
}
?>

</body>
</html>



// Make a file index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="searchdata.php" method="post" >
<h1>Enter College Name</h1>
<input type="text" name="searchterm"
style="height:30px; width:270px; border-radius:2px 0 0 2px; border:none; font-size:20px; color:#808080; background:#999" />
<input type="submit"/>
</form>
</body>
</html>


// Database


--
--  Create Database Name: `college`
--

-- --------------------------------------------------------

--
-- Table name -  `student`
--

CREATE TABLE IF NOT EXISTS `student` (
  `name` varchar(11) NOT NULL,
  `class` varchar(22) NOT NULL,
  `rollno` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `student`
--

INSERT INTO `student` (`name`, `class`, `rollno`) VALUES
('a', '1', 1),
('b', '2', 2);






Tuesday, October 15, 2013

SQL Querries

1  // Create a table
CREATE TABLE student
(
id int,
name varchar(255),
class varchar(255),
rollno int

)
2  //INSERT values in table
INSERT INTO student (id, name, class, rollno)
VALUES ('1','Smile','Btech','1');

3   //DISPLAY values using select command

SELECT * FROM student;

4  //Find UNIQUE VALUES, not duplicate values  (Distint Command)

SELECT DISTINCT name FROM student;

5  // WHERE CONDITION

SELECT * FROM student
WHERE rollno='1';

6.  AND OPERATOR

SELECT * FROM student
WHERE name='smile'
AND rollno='1';

7.  OR OPERATOR

SELECT * FROM student
WHERE name='smile'
OR rollno='2';

8.  ORDER BY ( Assending order)

SELECT * FROM student
ORDER BY name;

9.  ORDER BY (Desending Order)

SELECT * FROM student
ORDER BY name DESC;

10. ORDER BY  ( Multiple Columns)

                SELECT * FROM student
ORDER BY name,class;


11. // UPDATE Command

                UPDATE student
SET name='smile1'
WHERE name='smile';

12. // DELETE Command

                DELETE FROM student
WHERE name='honey' AND rollno='2';

13. // SELECT Top Rows from a table

                SELECT *
FROM student
WHERE rollno <=5;

14. // LIKE Command ( for Search)

                SELECT * FROM student
WHERE name LIKE 'd%';

15. // LIKE Command (with % Symbol )

                SELECT * FROM student
WHERE name LIKE '%mi%';

16. //  NOT LIKE Operator

                SELECT * FROM student
WHERE name NOT LIKE '%mi%';

17. // LIKE OPERATOR  ( With Under Score    _  Operator)

                SELECT * FROM student
WHERE name LIKE '_mi';

18.// LIKE OPERATOR ( With Multiple Operators)

SELECT * FROM student
WHERE name LIKE 's_i_e1';

19. // IN OPERATOR

            SELECT * FROM student
WHERE name IN ('smile1','deepak');

20. // Between Operator

            SELECT * FROM student
WHERE rollno BETWEEN 1 AND 20;

21. // CHANGE Column Name in a Table

            SELECT name AS name1, rollno AS rollno1
FROM student;

22.// UNION, making 2 tables, one student ( id, name, rollno, class) and 2nd (rollno, firstname,lastname)

            SELECT rollno FROM student
UNION
SELECT rollno FROM student1
ORDER BY rollno;

23. // LIMIT STATEMENT


      SELECT * FROM student LIMIT 6;

24. LIMIT STATEMENT (But in certain situations, you may need to pick up a set of records from a particular offset. Here is an example, which picks up 3 records starting from 3rd position)

                SELECT * FROM student LIMIT 5 OFFSET 3;

25. GROUP BY

                    SELECT name, SUM(salary) FROM student GROUP BY name;

26. NOT NULL STATEMENT

         CREATE TABLE student( id INT PRIMARY KEY     NOT NULL,name TEXT NOT NULL,);

27. DEFAULT Constraint

The DEFAULT constraint provides a default value to a column when the INSERT INTO statement does not provide a specific value.
      CREATE TABLE student(ID INT PRIMARY KEY ,NAME TEXT ,SALARY REAL DEFAULT 50000.00);

28 . Primary Key

      CREATE TABLE student(id INT PRIMARY KEY NOT NULL, name TEXT NOT NULL,);

29. CHECK Constraint

The CHECK Constraint enables a condition to check the value being entered into a record. If the condition evaluates to false, the record violates the constraint and isn't entered into the table.
      CREATE TABLE student(ID INT PRIMARY KEY ,NAME  TEXT,SALARY REAL CHECK(SALARY > 0));


















1.  //Creating a Database

                Create database college;

2. //Changing a Database

                Use college;

3.//using where condition for selecting a particular column

                Select name from student where id=’2’;

4.//showing all tables in a particular database

                Show tables;

5.//adding  a column to an exciting table;

                Alter table student add address varchar(255);

6.//dropping a table

                Drop table student;

7.//IS NULL attribute

                Select * from Student where class IS NULL;

8.//concatenation of two column in a tables(CONCAT)

                Select  concat(name,’-‘,class) as ‘product_desc’ from student;

9.//COUNT(*) function for counting the number of rows in table

                Select count(*) as ‘count’ from student;

10.//MAX(column_name) function for selecting the max value of a particular column

                Select MAX(rollno) from student;

11.//MIN(column_name) function for selecting the minimum value of a particular column

                Select MIN(rollno) from student;

12.//AVG(column_name) function for selecting the average  value of a particular column

                Select AVG(rollno) from student;

13.//SUM(column_name) function for selecting the SUM of a particular column

                Select SUM(rollno) from student;

14.//dropping a particular column of a table

                Alter  table student drop class;

15.//AUTO_INCREMENT (must be defined for key values only)

                Alter table student add pass_no int key auto_increment;

16.//joining data of two tables

Select student.id,student.name,student9.rollno from student,student9 where student.name=student9.name;

17.//joining of two tables using LEFT JOIN

Select student.id,student.name,student9.rollno from student LEFT JOIN student9 on student.name=student9.name;

18.//joining of two tables using RIGHT JOIN

Select student.id,student.name,student9.rollno from student RIGHT  JOIN student9 on student.name=student9.name;

19.//describing the complete table;

                Describe student;

20.//updating a column of a table using MODIFY

                Alter table student modify column name char(20);

21.//renaming a column

                Alter table student rename as all_student;

22.//use of HAVING

Select student.id,student.name,student9.rollno from student RIGHT  JOIN student9 on student.name=student9.name group by name having count(student.rollno)>5;

23.//use of UCASE() for converting a column from lowercase to uppercase

                Select ucase(name) from student;

24.//use of LCASE() for converting a column from uppercase to lowercase

                Select Lcase(name) from student;

25.//selecting  substrings from a table column using SUBSTRING

                Select substring(name,1,3) from student;
                1 defines start of substring
               2 defines it’s length

26.//foreign key

Let us consider that ‘id’ is the primary key of student table and it is referenced to a second table called ‘account’
Create table account(account_no int not null,account_id int primary
Key, id int foreign key references student(id));

27.//Procedures in mysql

                Procedures in mysql are sequence of a group of statements, that are defined together for later use. In simple words procedures in mysql are almost similar to functions of c++.which can be called from anywhere in a program whenever they required. Below shown a simple example :
                Delimiter //
                Create procedure mynameis( s VARCHAR(255))
                                Begin
                                Set @x=s;
                                End
                //
                Using this procedure
                Delimiter  ;
                Call mynameis(‘smile Mittal’);
                Select @x;
This will display the value stored in x in the form table. Here delimiters are used for  separating the executable statement followed by ‘;’ to define a group of statements.

28.//dropping a procedure

                Drop procedure mynameis;

29.//creating function in mysql

                Create function mydata(s char(20))
                Returns char(50) deterministic
Return concat(‘amandeep’,’ ‘, s);
Calling this function
Select mydata(‘singh’);

30.//Dropping a function

                Drop function mydata(‘singh’);

31.//showing list of all tables in a database

                Show tables;

32.//showing all tables with full information

                Show full tables;

Views in MySql
                A view is a virtual table, which looks like a table .views can restrict a user to specific rows or column and hence it will result in providing security. These can be used to provide aggregate of multiple tables or multiple columns from multiple tables. Views are not the part of physical schema. Views provide security in such a way that, if we want only a few no of column accessible to a user ,but remaining are not, then  we declare these columns as a part of view. 

33.//creating a view for a single table

                Create  view  student_view as select name, rollno from student where rollno=646;

34.//creating views using multiple UNION oprerator

                 create view my_view as select * from student where id=3
               union select * from student where name='aman'
               union select * from Student where rollno=646;

35.//showing the created view

                Select * from my_view;

Index in mysql
                Use of indexes in mysql improves the performance for searching in database. For example if we have a table student, which consists of a no. of fields like name,class,rollno,id. If we declare index for field ‘class’, then it will become easier to search for student based on their class. As compared to searching the whole table, if index is not defined.
Practically index can be considered as a type of tables, which keeps primary key or index field and a pointer to each record in the actual table.
INDEX speed up SELECT but speed down INSERT. But speed up effect is greater than speed down. Delicacy is not allowed while we define index for a particular column.

36.//use of UNIQUE INDEX  

                Create unique index my_name on student (name);

37.//displaying index information

                Show index from student;

38.//use of SIMPLE INDEX

                Create index my_data on student(name);
               //delicacy is allowed in simpleindex

39.//ALTER command to add and drop UNIQUE  index

                Alter table student ADD UNIQUE my_name(student_roll);

40.//ALTER command to add and drop SIMPLE INDEX

                Alter  table student ADD INDEX my_name(student_roll);

41.//adding FULLTEXT Index

                Alter table student ADD FULLTEXT my_name(name);


TEMPORARY TABLES
                Temporary tables are used to store temporary data. Temporary tables would got destroyed if present session for a user is destroyed. Temporary tables remains alive till the user’s session is alive.

42.//creating temporary tables

                Create temporary table allstudent(id int,name varchar(255));
                Insert into allstudent values (1,’smile mittal’);
                Select   * from allstudent;

When SHOW TABLES command is used than ,it will not display the temporary tables in the shown list of tables. And if the current mysql session is closed then SELECT command for will not display any data in this  temporary  tables.


43.// getting information for complete table structure.

                Show create table student;

This will display all the information related to the table student. This  information will include the following :
UNIQUE KEY,PRIMARY KEY,FULLTEXT KEY,DAFAULT CHARSET.



TRIGGERS IN MYSQL
                A trigger is a set of code that is being executed is response to an event. It is of two type BEFORE and AFTER trigger. Triggers can only be associated with real tables not with temporary or views. Triggers provide interactivity to the tables ,in response to a particular event. These also provide the facility of linking of various operations like INSERT,DELETE,UPDATE together to be executed on separate tables at occurrence of an particular event.
                Below is an example shown which gives you a simple understanding of operation of triggers. In this example we have taken two table named as STUD_TRIGGER1 and STUD_TRIGGER2,having columns COL1_TAB1 and COL1_TAB2 respectivily.

44.//Creating a TRIGGER named my_trigger

                Delimiter //
                Create trigger my_trigger before insert on stud_trigger1
                For each row begin
                Insert into stud_trigger2 set col1_tab2=new.col1_tab1;
                End;
                //
45.// using TRIGGERS ,following statement will insert data in table STUD_TRIGGER1,and hence as defined in the MY_TRIGGER statements, this will insert the same data in STUD_TRIGGER2 table.

                Insert into stud_trigger1  values(1),(3),(1),(7),(6);
                Select * from stud_trigger1;      //this will display the content of stud_trigger1 table.
Select * from stud_trigger2;     //This will display the same content as per statement defined in MY_TRIGGER
.

Cursors in MYSQL
MySQl cursor is a read only (means you can not update table, for which cursor is created),non scrollable(means you can not change the order of fetching, which is being defined in the select statement).and in addition to these cursor is asensitive (means it works on actual data). Cursors are used when more than one rows are expected to be retrieved. Cursors must be declared and its definition contains a query. Cursors are well supported inside procedures and functions. It must be opened before processing and closed after processing. A number of cursors can be inside a procedure and function ,but should be of different names.


46.//Defining cursor in procedure
                delimiter //
 create procedure my_cursor3()
                begin
                declare d int default 0;
                declare id,rollno,student_roll int;
                declare name,class varchar(255);
                declare curs cursor for select name from student
                declare continue handler for not found set d=1;
                open curs;
                lbl:loop
                if d=1 then
                leave lbl;
end if;
                if not d=1 then
                fetch curs into id;
                insert into account values(id);
                 end if;
                end loop;
                close curs;
                end;
                //
Query OK, 0 rows affected (0.00 sec)
                Using the defined cursor
 delimiter ;
 call my_cursor3();
Query OK, 1 row affected (0.01 sec)
                Showing data of selected table
select * from account;