0% found this document useful (0 votes)
5 views

rdbms-record

RDBMS RECORD
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

rdbms-record

RDBMS RECORD
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 85

Rdbms - Record

Computer Science (Anna University)

Downloaded by Priyanga Sankaranarayanan


Studocu is not sponsored or endorsed by any college or university

Downloaded by Priyanga Sankaranarayanan


DEPARTMENT OF COMPUTER ENGINEERING

RECORD NOTE BOOK

4052470 – RELATIONAL DATABASE AND MANAGEMENT


SYSTEMS PRACTICAL

Register No.:

Downloaded by Priyanga Sankaranarayanan


DEPARTMENT OF COMPUTER ENGINEERING

BONAFIDE CERTIFICATE
4052470 – RELATIONAL DATABASE AND MANAGEMENT SYSTEMS
PRACTICAL

Name: …………………………………………………
Reg. No.: ……………….…………………………….
Roll No.: ………………………………………………
Year/Semester: …………………………………….

Certified that this is a bonafide record of work done by


……………………………………………………… in the RELATIONAL
DATABASE AND MANAGEMENT SYSTEMS LABORATORY during the
period March 2022 to May 2022.
RECORD MARKS

STAFF-IN-CHARGE HEAD OF THE DEPARTMENT

Submitted for Practical Examination held on ……………………………

INTERNAL EXAMINER EXTERNAL EXAMINER

Downloaded by Priyanga Sankaranarayanan


EXPT
DATE INDEX PAGE
MARKS
STAFF
NO. NAME OF THE EXPERIMENT NO. SIGNATURE

PART-A
1 MY SQL INSTALLATION AND CONFIGURATION

2 STUDY OF BASIC MYSQL COMMANDS

3 STUDY OF VIEWING MYSQL COMMANDS

STUDY OF MYSQL COMMANDS INVOLVE COMPOUND


4 CONDITIONS

5 TRANSACTION MANAGEMENT

6 NORMALIZATION

7 VIEW CREATION AND MANIPULATION

8 LIBRARY TABLE CREATION AND MANIPULATION

PART-B
9 FLOW CONTROL MANAGEMENT IN BANK DATABASE

10 JOINS

11 STORED PROCEDURE

12 TRIGGER

13 STORED FUNCTION

14 CURSOR

15 CONNECT PHP WITH MYSQL

OBSERVATION MARK

RECORD MARK
TOTAL

Downloaded by Priyanga Sankaranarayanan


Ex. No. : 1
Date:
MY SQL INSTALLATION AND CONFIGURATION

Aim:
To Install, configure and connect to MySQL Server and MySQL Workbench in Windows. And
to Create a Database, backup and restore the Database.

Hardware Requirement:
1. Computer System with Pentium Processor
2. Printer

Software Requirement:
1. MySQL Server 5.1
2. MySQL Workbench 5.2

Procedure:
Installation for MySQL Server:
1. Download and open installation file for MySQL Server and press “Next” in Setup Wizard.
2. Choose “Typical” setup type and click “Next” and “Install” in option in Setup
Wizard for Installation Settings.
3. Click “Next” and “Next” in MySQL Enterprise Server and MySQL Enterprise
Monitor Service window.
4. To Complete the Installation Process, Click Check box in “Configure & Register the
MySQL Server Now” options and Click “Finish” Button.
5. In MySQL Server Instance Configuration Wizard click “Next” and
Choose “Detailed Configuration” and Click “Next”.
6. Select “Developer Machine” and click “Next” for to select server type.
7. Select “Multifunctional Database” and click “Next” for to select Database usage.
8. Default Drive “C” and Click “Next” in InnoDBTablespace Settings.
9. Select “Decision Support (DSS)/OLAP” and click “Next” for to set the number of
concurrent connections to the server.
10. Check the Options “Enable TCP/IP Networking” and “Enable Strict Mode and
Click “Next” to Set the Networking Option.
11. Select “Standard Character Set” and click “Next” to select the default character set.
12. Check the options “Install as Window Service” and “Include Bin Directory in
Windows PATH” and Click “Next” to set the Windows options.[ Service Name
: MySQL].
13. Give the “Root Password” and Check the option “Enable root access from remote

Downloaded by Priyanga Sankaranarayanan


machines” and Do Not Check the option “Create An Anonymous Account” and
Click “Next” to set the security options.
14. In Ready to execute window click “Execute” option.
15. In the Last wizard the process checked the “Configuration file Created”,
“Windows service MySQL installed”, “Service started successfully”,” Security
Settings applied” Click “Finish” option to close the wizard.
Output:

MySQL Server Installation and Configration:

Downloaded by Priyanga Sankaranarayanan


Downloaded by Priyanga Sankaranarayanan
Downloaded by Priyanga Sankaranarayanan
Downloaded by Priyanga Sankaranarayanan
Downloaded by Priyanga Sankaranarayanan
Downloaded by Priyanga Sankaranarayanan
Installation for MySQL Workbench:

1. Download and open installation file for MySQL Workbench and press “Next” in Setup
Wizard and press ‘Next’ in destination folder wizard.
2. Choose ‘Complete’ and click ‘Next’ in Setup Type wizard and click ‘Install’ in Ready to
install the Program wizard.
3. After Installation process click ‘Finish’ option.

Downloaded by Priyanga Sankaranarayanan


Downloaded by Priyanga Sankaranarayanan
Downloaded by Priyanga Sankaranarayanan
Creating a Database:

1. Open Mysql Workbench. [ ChooseMysql workbench in Start/All programs/Mysql/].


2. In MySql workbench Home Page Click ‘New Connection’ towards the bottom left of Mysql
Workbench.
3. In the ‘Setup New Connection ‘ wizard type the connection name and click
‘Test Connection’option.
4. Now Type your password and click ‘Save password in valut’ check box and click ‘Ok’.
5. Now Mysql Workbench should say ‘Connection parameters are correct’ and click ‘Ok’ and
again click ‘Ok’ to accept the Connection settings.
6. Now the Query working environment is opened.
7. In this query window, click Icon to create a database or to type the query and execute to create
database.

Downloaded by Priyanga Sankaranarayanan


Downloaded by Priyanga Sankaranarayanan
Backup the Database:

1. In Home Page Under Server Administration Click ‘Manage Import/Export’ option.


2. In Task and Object Browser Click ‘Data Export’ option.
3. In Data Export window Select Database name and all Tables
4. Click ‘Export to Dump Project Folder’ and type the path name and file name.
5. Click ‘Start Export’

Downloaded by Priyanga Sankaranarayanan


Downloaded by Priyanga Sankaranarayanan
Restore the Database:

1. In Home Page Under Server Administration Click ‘Manage Import/Export’ option.


2. In Task and Object Browser Click ‘Data Import/Restore’ option.
3. In Data Import/Restore window Select ‘Import from Dump Project folder’.
4. Type the path of the Backup file and click ‘Load Folder Contains’ .
5. Click ‘Start Import’.

Downloaded by Priyanga Sankaranarayanan


Result:

Thus the Mysql Installation, Configuration and connecting to Mysql Server and Mysql
Workbench in Windows was done successfully. And created a Database, backup and restore the
Database also done successfully.

Downloaded by Priyanga Sankaranarayanan


Ex. No. : 2
Date:
STUDY OF BASIC MYSQL COMMANDS

Aim:
To study Basic MySQL commands (create database, create table, use, drop, insert) and execute
the following queries using these commands:
 Create a database named ‘employee’.

 Use the database ‘employee’ and create a table ‘emp’ with attributes ‘ename’, ‘ecity’,
‘salary’, ‘enumber’, ‘eaddress’, ‘deptname’.

 Create another table ‘Company’ with attributes ‘cname’, ‘ccity’, ‘empnumber’ in the
database ‘employee’.

Hardware Requirement:

1. Computer System with Pentium Processor


2. Printer

Software Requirement:

1. MySQL Server 5.1


2. MySQL Workbench 5.2

Procedure:

i) Create a database ‘employee’

mysql> create database employee;

ii) Using the database ‘employee’


mysql> use employee;

Downloaded by Priyanga Sankaranarayanan


iii) Create a table ‘emp’

mysql> create table emp(ename varchar(20),ecity varchar(20),salary


int(6),enumber varchar(6),eaddress varchar(20),deptname varchar(10));

iv) Describe ‘emp’ table

mysql> describe emp;

v) Inserting rows in ‘emp’

mysql> insert into emp values (‘Vignesh’, ’Chennai’, 25000, ’T10001’,


’Tambaram’, ’IT’);

Downloaded by Priyanga Sankaranarayanan


mysql> select * from emp;

Downloaded by Priyanga Sankaranarayanan


vi) Create table ‘company’

mysql> create table company(cname varchar(20),ccity varchar(20),empnumber


int(6));

vii) Inserting rows in ‘company’

mysql> insert into company values(‘TCS’,’Chennai’,12000);

Downloaded by Priyanga Sankaranarayanan


mysql> select * from company;

viii) Dropping table ‘emp’

mysql> drop database employee;


mysql> drop table emp;

Result:

Thus the database employee is created with two entities and performed the basic MySQL
commands successfully.

Downloaded by Priyanga Sankaranarayanan


Ex. No. : 3
Date:

STUDY OF VIEWING MYSQL COMMANDS

Aim:
To study the viewing commands (select, update) and execute the following queries using these
commands:
 Find the names of all employees who live in Chennai.

 Increase the salary of all employees by Rs.5,000.

 Change the company city to Chennai where the company name is ‘TCS’.

Hardware Requirement:

1. Computer System with Pentium Processor


2. Printer

Software Requirement:

1. MySQL Server 5.1


2. MySQL Workbench 5.2

Procedure:

i) Using the database ‘employee’

mysql> use employee;

Downloaded by Priyanga Sankaranarayanan


ii) Viewing rows in table ‘emp'

mysql> select * from emp;

iii) Finding the names of all employees who live in Chennai

mysql> select * from emp where ecity=’Chennai’;

mysql> select ename from emp where ecity=’Chennai’;

Downloaded by Priyanga Sankaranarayanan


iv) Increasing the salary of all employees by Rs. 5000/-

mysql> update emp set salary=salary+5000;

mysql> select * from emp;

v) Viewing the rows in the table ‘company’

mysql> select * from company;

Downloaded by Priyanga Sankaranarayanan


vi) Changing the company city to Chennai where the company name is ‘TCS’

mysql> update company set ccity=’Chennai’ where cname=’TCS’;

mysql> select * from company;

mysql> select * from company where cname=’TCS’;

Result:

Thus the database employee is created with two entities and performed the viewing commands
successfully.

Downloaded by Priyanga Sankaranarayanan


Ex. No. : 4
Date:

STUDY OF MYSQL COMMANDS INVOLVE COMPOUND CONDITIONS

Aim:
To study the commands that involve compound conditions (and, or, in, not in, between, not
between, like, not like) and execute the following queries using these commands:
 Find the names of all employees who live in ‘Chennai’ and whose salary is between Rs.20,000 to
Rs.30,000.

 Find the names of all employees whose names begin with either letter ‘A’ or ‘B’.

 Find the company names where the company city is ‘Chennai’ and the number of employees is
not between 5000 and 10,000.

 Find the names of all companies that do not end with letter ‘A’ .

Hardware Requirement:

1. Computer System with Pentium Processor


2. Printer

Software Requirement:

1. MySQL Server 5.1


2. MySQL Workbench 5.2

Procedure:

i) Finding the names of all employees who live in ‘Chennai’ and whose salary is
between Rs.20000 to Rs.30000.

mysql> use employee;

Downloaded by Priyanga Sankaranarayanan


mysql> select * from emp;

mysql> select ename from emp where ecity=’Chennai’ AND salary BETWEEN
20000 and 30000;

ii) Finding the name of all employees whose names begin with either letter ‘A’ or ‘B’.

mysql> select ename from emp where ename LIKE ‘A%’ OR ename LIKE ‘B%’;

Downloaded by Priyanga Sankaranarayanan


iii) Finding the company names where the company city is ‘Chennai’ and the number
of employees is not between 5000 and 10000.

mysql> select * from company;

mysql> select distinct cname from company where ccity=’Chennai’ AND


empnumber NOT BETWEEN 5000 AND 10000;

iv) Finding the names of all companies that do not end with letter ‘A’.

mysql> select distinct cname from company where cname NOT LIKE ‘%A’;

Downloaded by Priyanga Sankaranarayanan


Result:

Thus the database employee is created with two entities and performed the commands that
involve compound conditions successfully.

Downloaded by Priyanga Sankaranarayanan


Ex. No. : 5
Date:

TRANSACTION MANAGEMENT

Aim:

To Create a Database ‘polytechnic_college’ and to create two users namely ‘staff ’and `student’.
 To grant all privileges to the users ‘Staff ’and grant only ‘create’ privileges to
‘student’ user and verify the same.
 To revoke all privileges to the 2 users and verify the same.
 To implement the following transaction control statements.
i) Commit
ii) Rollback
iii) Save point

Hardware Requirement:

1. Computer System with Pentium Processor


2. Printer

Software Requirement:

1. MySQL Server 5.1


2. MySQL Workbench 5.2

Procedure:

Creating a database ‘polytechnic_college’

mysql> create database polytechnic_college;

Downloaded by Priyanga Sankaranarayanan


mysql> show database;

Creating a user staff

mysql> create user staff identified by ‘staff123’;

Creating an user student

mysql> create user staff identified by ‘student123’;

Querying users available

mysql> select user,host from mysql.user;

Downloaded by Priyanga Sankaranarayanan


Granting all privileges to the user staff

mysql> grant all privileges on *.* to ‘staff’;


mysql> flush privileges;

Granding only ‘create’ privilege to the user student

mysql> grant create on polytechnic_college to ‘student’;


mysql> flush privileges;

Showing permitted grants for the user staff

mysql> show grants for ‘staff’;

Downloaded by Priyanga Sankaranarayanan


Granting only ‘create’ privilege to the user student

mysql> grant create on *.* to student;

Showing permitted grants for the user student

mysql> show grants for ‘student’;

Switching to the user staff

mysql> select user();

Verifying the privileges granted to the user staff

mysql> create database computer;

mysql> use computer;

Downloaded by Priyanga Sankaranarayanan


mysql> create table staff_names(name varchar(50));

mysql> insert into staff_names values(‘Suresh’);


mysql> insert into staff_names values(‘Akash’);

mysql> select * from staff_names;

mysql> delete from staff_names;

Switching to the user student

mysql> select user();

Verifying the privilege granted to the user student

mysql> create database student1;


musql> use student1;

Downloaded by Priyanga Sankaranarayanan


mysql> create table comp_student(name varchar(40));
mysql> insert into comp_student values(‘Sowmiya’);
mysql> select * from comp_student;

Now switching to the root user

mysql> select user();

Revoking privileges granted to the user staff

mysql> revoke all privileges,grant option from staff;

Revoking privileges granted to the user student

mysql> revoke create on *.* from student;

Downloaded by Priyanga Sankaranarayanan


Verifying the privileges after revoking

mysql> create database poly;

b) Implement the following transaction control statements

i) Commit

Creating a table

mysql> create table leaders(name varchar(30) primary key);

Staring the transaction

mysql> start transaction;

Inserting rows into the table leaders

Using commit

mysql> commit;

Downloaded by Priyanga Sankaranarayanan


Querying the table leaders

mysql> select * from leaders;

ii) Rollback
Starting transaction

mysql> start transaction;

Inserting rows into the table leaders

Using rollback to undo changes in the current transaction

mysql> rollback;

Querying the table leaders to view the effect of rollback

mysql> select * from leaders;

Downloaded by Priyanga Sankaranarayanan


iii) Savepoint

Creating a table

mysql> create table num_seq(i int);

Starting the transaction

mysql> start transaction;

Inserting a row into the table num_seq

Setting savepoint marker

mysql> savepoint savepoint_eg;

Again inserting a row

Using savepoint marker to rollback

mysql> rollback to savepoint savepoint_eg;

Again inserting a row into the table

Downloaded by Priyanga Sankaranarayanan


Now commit the changes

mysql> commit;

Verifying the effect of using savepoint

mysql> select * from num_seq;

Result:

Thus the users are created and applied the grant and revoke privileges and also implement the
Transaction Management command successfully.

Downloaded by Priyanga Sankaranarayanan


Ex. No. : 6
Date:

NORMALIZATION

Aim:

To Create table ‘author’ with the following structure author_id author_name address mobile
book_title pages published_on
i) Insert 4 books published by 3 authors each. (12 records)
ii) Fetch all the rows and observe how the data duplicated.
iii) Apply 1st and 2nd normal forms to fix it.

Hardware Requirement:

1. Computer System with Pentium Processor


2. Printer

Software Requirement:

1. MySQL Server 5.1


2. MySQL Workbench 5.2

Procedure:

Using the database

mysql> use polytechnic;

Creating a table author

mysql> create table author (author_id int(3),author_name varchar(60),address


varchar(100),mobile char(10),book_title varchar(60),page int(3),published_on
date);

Downloaded by Priyanga Sankaranarayanan


i) Inserting rows into the table author

Downloaded by Priyanga Sankaranarayanan


ii) Fetching all the rows

mysql> select * from author;

iii) Applying first and second normal forms to avoid duplicated entries i.e., Splitting
the table into two tables author_information and book_titles1.
Creating a new table containing author information, avoiding duplication.

mysql> create table author_information(author_id int(3) primary


key,author_name varchar(60),address varchar(100),mobile char(10));

Querying the table author_information

mysql> select * from author_information;

Downloaded by Priyanga Sankaranarayanan


Creating a table book_detail1 containing book information using foreign key which
reference the primary key of book_information

mysql> create table book_details1(author_id int(3),book_title varchar(60),pages


int(3),published_on date,foreign key(author_id) references
author_information(author_id));

Inserting rows into book_detail1 using author table

Querying the table book_details

mysql> select * from book_details1;

Now for displaying both the tables information, use the following query (ie Natural
join)

Downloaded by Priyanga Sankaranarayanan


mysql> select author_name,address,mobile,book_title,pages,published_on from
author_information natural join book_details1;

Result:
Thus the author table is created and inserted the values for the observation of the created table,
there is a duplicated records. For that applied the 1st and 2nd normal form successfully and removed the
duplicated entries.

Downloaded by Priyanga Sankaranarayanan


Ex. No. : 7
Date:

VIEW CREATION AND MANIPULATION

Aim:
To study the commands for views and execute the following queries using these commands:

 Create a view having ename and ecity


 In the above view change the ecity to ‘Chennai’ where ename is ‘John’.
 Create a view having attributes from both the tables.
 Update the above view and increase the salary of all employees of IT
department by Rs.1000.

Hardware Requirement:

1. Computer System with Pentium Processor


2. Printer

Software Requirement:

1. MySQL Server 5.1


2. MySQL Workbench 5.2

Procedure:

i) Using database

mysql> use employee;

ii) Create a view having ename and city

mysql> create view location_view1 as selection ename,ecity, from emp;

Downloaded by Priyanga Sankaranarayanan


mysql> selecet * from emp;

mysql> select * from location_view;

iii) In the above view changing the ecity to ‘Chennai’ where ename is ‘John’.

mysql> update location_view set ecity=’Chennai’ where ename=’John’;

Downloaded by Priyanga Sankaranarayanan


mysql> select * from location_view;

mysql> select * from emp;

iv) Create a view having attributes from both the table

mysql> create view both_table_view as select distinct ename,salary,deptname,ccity


from emp inner join company on ecity=ccity;

Downloaded by Priyanga Sankaranarayanan


mysql> select * from both_table_view;

v) Update the view and increase the salary of all employees of IT deparment
by Rs.1000

mysql> create view new_view as select ename,salary,deptname from emp;

mysql> select * from new_view;

mysql> update new_view set salary=salary+1000 where deptname=’IT’;

Downloaded by Priyanga Sankaranarayanan


mysql> select * from new_view;

mysql> select * from emp;

Result:

Thus the view is created and displayed all the requests successfully.

Downloaded by Priyanga Sankaranarayanan


Ex. No. : 8
Date:

LIBRARY TABLE CREATION AND MANIPULATION

Aim:

To Create a library table with proper fields. Create another table called library1 and insert rows
from library table.
Hint:
CREATE TABLE new_table LIKE original_table;
INSERT INTO new_table SELECT * FROM original_table;

Hardware Requirement:

1. Computer System with Pentium Processor


2. Printer

Software Requirement:

1. MySQL Server 5.1


2. MySQL Workbench 5.2

Procedure:

Using the database

mysql> use polytechnic;

Creating a table library

mysql> create table library(bookno int(4) primary key, bookname varchar(80),


author varchar(50),publisher varchar(40), edition varchar(20), published_on date,
price decimal(7,2));

Downloaded by Priyanga Sankaranarayanan


Inserting rows into the table library

Querying the table library

mysql> select * from library;

Downloaded by Priyanga Sankaranarayanan


Creating another table library1 like the table library

mysql> create table library1 like library;


mysql> describe library1;

Inserting rows into the table library1 from the table library

mysql> insert into library1 select * from library;

Querying the table library1

mysql> select * from library1;

Result:
Thus the library table is created and inserted the values into another table library1
successfully.

Downloaded by Priyanga Sankaranarayanan


Ex. No. : 9
Date:

FLOW CONTROL MANAGEMENT IN BANK DATABASE

Aim:
To Create a table to store the details of a customer in a Bank. Do some transactions like
withdrawal, deposit. Find the Balance amount(Credit Limit). Based on customer’s credit limit, write a
program using IF or CASE flow control statements to find the customer levels namely SILVER,
GOLD or PLATINUM.

If the Credit limit is

 greater than 50K, then the customer level is PLATINUM

 less than 50K and greater than 10K, then the customer level is GOLD

 less than 10K, then the customer level is SILVER

Hardware Requirement:

1. Computer System with Pentium Processor


2. Printer

Software Requirement:

1. MySQL Server 5.1


2. MySQL Workbench 5.2

Procedure:

Using the database

mysql> use polytechnic;

Downloaded by Priyanga Sankaranarayanan


Creating a table

mysql> create table bank(customer_id char(6), custname varchar(30), withdrawal


int(8), deposit int(8), balance int(8));

Inserting rows into the table

Using query to view the data

mysql> select * from bank;

Doing withdrawal transaction and finding the balance

mysql> update bank set withdrawal=30000 where customer_id=’IOB101’;


mysql> update bank set balance = balance - withdrawal where customer_id =
’IOB101’;

Downloaded by Priyanga Sankaranarayanan


Doing deposit transaction and finding the balance

mysql> update bank set deposit=30000 where customer_id=’IOB103’;


mysql> update bank set balance=balance+deposit where customer_id=’IOB103’;
mysql> select * from bank;

Program using IF flow control statement to find the customer level

(enter the following commands in the file ex9.sql using notepad)

Downloaded by Priyanga Sankaranarayanan


Executing the above procedure

mysql> source e:\mysqlprogram\ex9.sql

Calling the procedure to find the credit limit

mysql> call credit_limit(‘IOB101’,@cust_level);


mysql> select @cust_level;
mysql> call credit_limit(‘IOB102’,@cust_level);
mysql> select @cust_level;
mysql> call credit_limit(‘IOB103’,@cust_level);
mysql> select @cust_level;

Downloaded by Priyanga Sankaranarayanan


Result:

Thus the flow control statements are used in a bank table and retrieve the information
successfully.

Downloaded by Priyanga Sankaranarayanan


Ex. No. : 10
Date:

JOINS

Aim:
To Create two tables with the following structure.
a) users - table name
user_id - UNSIGNED, INT, AUTO INCREMENT, PRIMARY KEY
username - VARCHAR (60) password - VARCHAR (128) ,email - VARCHAR (255)
b) users_profiles
user_id - FOREIGN KEY refers to user_id field of user table first_name -
VARCHAR(60), last_name - VARCHAR(60) mobile - VARCHAR(15)

i) SELECT all the users along with their profile


details. (Hint: Use INNER JOIN)
ii) SELECT the users who do not have profiles
(Hint: USE LEFT JOIN and exclude the rows generated with NULL values from joining table)

Hardware Requirement:

1. Computer System with Pentium Processor


2. Printer

Software Requirement:

1. MySQL Server 5.1


2. MySQL Workbench 5.2

Procedure:

Using the database

mysql> use polytechnic;

Creating a table users

mysql> create table user(user_id int unsigned auto_increment primary key,


username varchar(60), password varchar(128), email varchar(255));

Downloaded by Priyanga Sankaranarayanan


mysql> describe users;

Creating a table users_profiles

mysql> create table user_profiles(user_id int unsigned, first_name varchar(60),


last_name varchar(60), mobile varchar(15), foreign key(user_id) reference
users(user_id));

mysql> describe users_profiles;

Inserting rows into users table

Downloaded by Priyanga Sankaranarayanan


Querying users table

mysql> select * from users;

Inserting rows into user_profiles table

Querying user_profiles table

mysql> select * from users_profiles;

i) Using INNER JOIN

mysql> select user.user_id,first_name,last_name,mobile,email from users inner join


users_profiles on users.user_id=users_profiles.user_id;

Downloaded by Priyanga Sankaranarayanan


ii) Using LEFT JOIN and excluding NULL values

mysql> select users.user_id,username,password,email, first_name,last_name, mobile


from users left outer join users_profiles on users.user_id=users_profiles.user_id;
where last_name is not null or mobile is not null;

Result:
Thus the join command is used to join the two tables and retrieved the information successfully.

Downloaded by Priyanga Sankaranarayanan


Ex. No. : 11
Date:

STORED PROCEDURE

Aim:
To Create an employee database and create a stored procedure that accepts employee_Id as input
and returns complete details of employee as output.

Hardware Requirement:

1. Computer System with Pentium Processor


2. Printer

Software Requirement:

1. MySQL Server 5.1


2. MySQL Workbench 5.2

Procedure:

Using the database

mysql> use polytechnic;

Creating a table employee

mysql> create table employee(employee_id int(3) primary key, name varchar(60),


address varchar(80), designatin varchar(20), age int(2), dob date, doap date,salary
int unsigned);

Downloaded by Priyanga Sankaranarayanan


Inserting rows into the table employee

Querying the employee table

mysql> select * from employee;

Creating a procedure

(enter the following commands in the file ex11.sql using notepad)

Executing the above procedure

mysql> source e:\mysqlprogram\ex11.sql

Downloaded by Priyanga Sankaranarayanan


Calling the procedure to get the output

mysql> call GetEmployeeDetails(203);


mysql> call GetEmployeeDetails(206);

Result:
Thus the stored procedure is created to accept the employee id and returns complete details of an
employee as output successfully.

Downloaded by Priyanga Sankaranarayanan


Ex. No. : 12
Date:

TRIGGER

Aim:
To Create two tables with the following structure
Authors
author_id - INT
name VARCHAR (60)
titles_count INT -- holds the total number numbers of titles authored.
Titles
author_id - INT
name VARCHAR (512) -- name of the title

a. Create a trigger to update the titles count field of respective row in authors table each
time a title gets inserted into titles table.
b. Create log table with the following structure author_id – INT
name VARCHAR (512) -- name of the title
status VARCHAR(25) --- ADDITION,DELETION,UPDATION
and insert an entry in that table each time the tile is added, deleted or updated. Use
a trigger to accomplish this.

Hardware Requirement:

1. Computer System with Pentium Processor


2. Printer

Software Requirement:

1. MySQL Server 5.1


2. MySQL Workbench 5.2

Procedure:

Using the database

mysql> use polytechnic;

Downloaded by Priyanga Sankaranarayanan


Creating a table author

mysql> create table authors(author_id int,name varchar(60),title_count int);

Inserting rows into the table authors

Querying the table authors

mysql> select * from authors;

Creating a table titles

mysql> create table titles(author_id int,name varchar(512);

Inserting rows into the table titles

Downloaded by Priyanga Sankaranarayanan


Querying the table titles

mysql> select * from titles;

Creating a trigger to update the title count of authors table when inserting into titles
table
(enter the following commands in the file ex12a.sql using notepad)

Executing the above trigger

mysql> source e:\mysqlprogram\ex12a.sql

Verifying trigger event

mysql> select * from authors;

Downloaded by Priyanga Sankaranarayanan


b) Creating a table log_table

Creating a trigger to insert into log_table when inserting into titles table

(enter the following commands in the file ex12b.sql using notepad)

Downloaded by Priyanga Sankaranarayanan


Executing the above trigger

mysql> source e:\mysqlprogram\ex12b.sql

Verifying trigger event

Downloaded by Priyanga Sankaranarayanan


Creating a trigger to insert into log_table when updating into titles table

(enter the following commands in the file ex12c.sql using notepad)

Executing the above trigger

mysql> source e:\mysqlprogram\ex12c.sql

Verifying trigger event

Downloaded by Priyanga Sankaranarayanan


Creating a trigger to insert into log_table when deleting from titles table

(enter the following commands in the file ex12d.sql using notepad)

Executing the above trigger

mysql> source e:\mysqlprogram\ex12d.sql

Verifying trigger event

Result:
Thus the trigger is created and updated the title count and log table is updated as added, deleted
and updated for each entry in author table successfully.

Downloaded by Priyanga Sankaranarayanan


Ex. No. : 13
Date:

STORED FUNCTION

Aim:
To create a table containing phone number, user name, address of the phone user. Write a
function to search the address using phone number.

Hardware Requirement:

1. Computer System with Pentium Processor


2. Printer

Software Requirement:

1. MySQL Server 5.1


2. MySQL Workbench 5.2

Procedure:

Using the database

mysql> use polytechnic;

mysql> Creating a table phonebook;

Inserting rows into the table phonebook

Downloaded by Priyanga Sankaranarayanan


Querying the table phonebook

mysql> select * from phonebook;

Creating a function to search the address using phone number

(enter the following commands in the file ex13.sql using notepad)

Executing the above function

mysql> source e:\mysqlprogram\ex13.sql

Searching the address using the created function

mysql> select find_address(phoneno) from phonebook where phoneno=12345;

mysql> select find_address(phoneno) from phonebook where phoneno=20312;

Downloaded by Priyanga Sankaranarayanan


mysql> select find_address(phoneno) from phonebook where phoneno=250524;

Result:
Thus the function is written to search address using phone number in phone book table
successfully.

Downloaded by Priyanga Sankaranarayanan


Ex. No. : 14
Date:

CURSOR

Aim:
To create a table to store the salary details of the employees in a company. Declare the cursor id
to contain employee number, employee name and net salary. Use cursor to update the employee.

Hardware Requirement:

1. Computer System with Pentium Processor


2. Printer

Software Requirement:

1. MySQL Server 5.1


2. MySQL Workbench 5.2

Procedure:

Using the database

mysql> use polytechnic;

Creating a table salary

mysql> creating a table salary;

Inserting rows into the table salary

Downloaded by Priyanga Sankaranarayanan


Querying the table salary

mysql> select * from salary;

Creating a cursor

(enter the following commands in the file ex14.sql using notepad)

Downloaded by Priyanga Sankaranarayanan


Executing the above function

mysql> source e:\mysqlprogram\ex14.sql

mysql> call cursorhandling(2);

Result:

Thus the cursor is created to update the employee salary successfully.

Downloaded by Priyanga Sankaranarayanan


Ex. No. : 15
Date:

CONNECT PHP WITH MYSQL

Aim:
To program to connect PHP with MySQL and create a database using PHP MySQL.

Hardware Requirement:

1. Computer System with Pentium Processor


2. Printer

Software Requirement:

1. MySQL Server 5.1


2. MySQL Workbench 5.2
3. WAMP SERVER

Procedure:

Enter the following PHP script in notepad

Downloaded by Priyanga Sankaranarayanan


 Save the above script in c:\wamp\www directory with .php extension

 Open a browser

 In the address bar of the browser, enter the

following http://localhost/database.php

Now PHP is connected with MySQL and the database named rdbms is created using
PHP MySQL.

Output:

Before running the php script database

After running the php script database

Downloaded by Priyanga Sankaranarayanan


Result:

Thus the program to connect PHP with MySQL and create a database using PHP MySQL
successfully.

Downloaded by Priyanga Sankaranarayanan

You might also like