Professional Documents
Culture Documents
AIM:
To perform operations such as Meta data, Collate, Joins, Views concept in Mysql.
PROCEDURE:
META DATA:
+------------+------------+--------+
+------------+------------+--------+
+------------+------------+--------+
+----------------------+-------+
| Variable_name | Value |
+----------------------+-------+
| character_set_system | utf8 |
+----------------------+-------+
+-----------------------+--------+
| Variable_name | Value |
+-----------------------+--------+
| character_set_results | latin1 |
+-----------------------+--------+
SURENDRAN.M
09I450
EXPT-6 OPEN SOURCE COMPUTING
COLLATE:
Using collate in SQL Statements (Collate is just to write in the Observation note and
record not for execution)
The COLLATE clause is used to override whatever the default collation is for a comparison.
COLLATE may be used in various parts of SQL statements.
+------------+------------+--------+
+------------+------------+--------+
+------------+------------+--------+
+---------------------------------------+-------------+
| table_name | table_type |
+---------------------------------------+-------------+
SURENDRAN.M
09I450
EXPT-6 OPEN SOURCE COMPUTING
| db | BASE TABLE |
SURENDRAN.M
09I450
EXPT-6 OPEN SOURCE COMPUTING
+---------------------------------------+-------------+
5. With AS:
+---------------------------------------+-------------+-------------+
SURENDRAN.M
09I450
EXPT-6 OPEN SOURCE COMPUTING
+---------------------------------------+-------------+-------------+
SURENDRAN.M
09I450
EXPT-6 OPEN SOURCE COMPUTING
SURENDRAN.M
09I450
EXPT-6 OPEN SOURCE COMPUTING
+---------------------------------------+-------------+-------------+
+---------------------------------------+-------------+
| table_name | table_type |
+---------------------------------------+-------------+
| db | BASE TABLE |
SURENDRAN.M
09I450
EXPT-6 OPEN SOURCE COMPUTING
SURENDRAN.M
09I450
EXPT-6 OPEN SOURCE COMPUTING
+---------------------------------------+-------------+
+-----------------------------------------+
+-----------------------------------------+
| VIEWS |
+-----------------------------------------+
8. With DISTINCT:
+---------------------------------------+------------------------------------+
SURENDRAN.M
09I450
EXPT-6 OPEN SOURCE COMPUTING
+---------------------------------------+------------------------------------+
SURENDRAN.M
09I450
EXPT-6 OPEN SOURCE COMPUTING
| db | BASE TABLE |
SURENDRAN.M
09I450
EXPT-6 OPEN SOURCE COMPUTING
+---------------------------------------+------------------------------------+
9. With WHERE:
+---------------------------------------+-------------+
| table_name | table_type |
+---------------------------------------+-------------+
SURENDRAN.M
09I450
EXPT-6 OPEN SOURCE COMPUTING
| db | BASE TABLE |
SURENDRAN.M
09I450
EXPT-6 OPEN SOURCE COMPUTING
+---------------------------------------+-------------+
10.With HAVING:
JOINS:
A join is a SQL query that is used to select the data from more than one table or views. When
you define multiple tables or views in the FROM clause of a query the MySQL performs a join
that linking the rows from multiple tables together.
Types of Joins :
INNER Joins
OUTER Joins
SURENDRAN.M
09I450
EXPT-6 OPEN SOURCE COMPUTING
SELF Joins
+--------------------+
| Tables_in_emp_info |
+--------------------+
| emp |
| employee |
+--------------------+
+----------+--------+------------+------------+
+----------+--------+------------+------------+
+----------+--------+------------+------------+
+--------+-----------+-----------+
SURENDRAN.M
09I450
EXPT-6 OPEN SOURCE COMPUTING
+--------+-----------+-----------+
| e1 | sunil | kumar |
| e2 | raj | kumar |
| e4 | guru | singh |
| e3 | ram | shankar |
| e9 | prem | kumar |
+--------+-----------+-----------+
INNER JOIN:
mysql> select * from emp inner join employee where emp.emp_id = employee.emp_id;
+----------+--------+------------+------------+--------+-----------+-----------+
+----------+--------+------------+------------+--------+-----------+-----------+
SURENDRAN.M
09I450
EXPT-6 OPEN SOURCE COMPUTING
+----------+--------+------------+------------+--------+-----------+-----------+
OUTER JOIN:
+----------+--------+------------+------------+--------+-----------+-----------+
+----------+--------+------------+------------+--------+-----------+-----------+
SURENDRAN.M
09I450
EXPT-6 OPEN SOURCE COMPUTING
+----------+--------+------------+------------+--------+-----------+-----------+
+----------+--------+------------+------------+--------+-----------+-----------+
+----------+--------+------------+------------+--------+-----------+-----------+
+----------+--------+------------+------------+--------+-----------+-----------+
SURENDRAN.M
09I450
EXPT-6 OPEN SOURCE COMPUTING
SELF JOIN:
+----------+--------+------------+------------+
+----------+--------+------------+------------+
+----------+--------+------------+------------+
VIEWS:
VIEW is a virtual table, which acts like a table but actually it contains no data. That is
based on the result set of a SELECT statement.
A VIEW consists rows and columns from one or more than one tables. A VIEW is a query
that’s stored as an object. A VIEW is nothing more than a way to select a subset of table’s
columns.
When you defined a view then you can reference it like any other table in a database. A
VIEW provides as a security mechanism also. VIEWS ensures that users are able to modify
and retrieve only that data which seen by them.
By using Views you can ensure about the security of data by restricting access to the
following data:
Specific columns of the tables.
Specific rows of the tables.
SURENDRAN.M
09I450
EXPT-6 OPEN SOURCE COMPUTING
mysql> create view it_employee as select * from emp where emp_id in(select emp_id
from employee)with CHECK OPTION;
+----------+--------+------------+------------+
+----------+--------+------------+------------+
+----------+--------+------------+------------+
RESULT:
Thus the concept of MetaData, Collate, Joins, Views are implemented in Mysql queries
successfully.
SURENDRAN.M
09I450