You are on page 1of 39

Roll No: 203 Exam Seat No :

AjaraMahavidyalaya ,Ajara
Dist Kolhapur
Department Of BCA

Certificate

This is to certify that Shri/Miss – Bhikale Vishwajit Vitthal has satisfactorily


completed to course of practical in computer prescribed by the Shivaji University
Kolhapur for B.C.A I / II / III Sem. I /II /III/IV/V/VI during the year 2022-2023.

Teacher in charge Examiner Head of Department

Date Date Date

INDEX
SR NO. Practical Name Page Date Signature

1 Perform the following


 Viewing all existing databases
 Create a database bca2;
 Viewing all the Tables in database.
 Create Table
 Insert , update and delete records in table
Save the table
2 PERFROM
 ADD COLUMN MOBILENUMBER TO TABLE
EMPLOYEE
 RENAME TABLE EMPLOUEE AS EMPLOYEE2
 EMPTY ALL THE ROWS OF EMPLOYEE2 TABLE
 DELETE TABLE EMPLOYEE2
 Create user bca123, grant and revoke
permissions to it for bca2

3 Perform the following:

 Simple Queries

 Simple Queries with Aggregate functions

 Queries with Aggregate functions (group by and


having clause)

4 Perform

 String functions
 Maths functions
 Date functions

5 Perform various joins in mysql

6 Title: SUBQUERIES WITH IN AND EXIST CLAUSE

7 SUBQUERIES WITH ANY AND ALL CLAUSES

8 CREATE VIEW, UPDATE IT AND THEN DELETE IT.

9 Develope a stored procedure that creates the list of names


AjaraMahavidyalaya,
of all the students in the student table in the sample Ajara
database
10 Develope a stored trigger that will add constraintDepartment
on on Of BCA
table employee while inserting data.

Assignment No:1 Date: Roll No : 203


Title: Perform the following
Viewing all existing databases
Create a database bca2;
Viewing all the Tables in database.
Create Table
Insert , update and delete records in table
Save the table.
mysql> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

| sample |

+--------------------+

4 rows in set (0.08 sec)


mysql> create database bca2;

Query OK, 1 row affected (0.00 sec)

mysql> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| bca2 |

| mysql |

| performance_schema |

| sample |
+--------------------+

5 rows in set (0.08 sec)


mysql> use bca2

Database changed

mysql> show tables;

Empty set (0.00 sec)

mysql> create table employee( empid int (4), emp_name varchar (10));

Query OK, 0 rows affected (0.24 sec)

mysql> show tables;

+----------------+

| Tables_in_bca2 |

+----------------+

| employee |

+----------------+

1 row in set (0.00 sec)

mysql> select * from employee;

+-------+----------+

| empid | emp_name |

+-------+----------+

| 1001 | ganesh |

| 1002 | ramesh |

| 1004 | ratna |

| 1003 | jyostna |

| 1005 | rama |

+-------+----------+

5 rows in set (0.00 sec)


mysql> create table clientmaster( clientno varchar(6),name varchar(20), address1 varchar(15), address2
varchar(15),city varchar(15), pincode int (8),state varchar(15), baldue float (10,2));

Query OK, 0 rows affected (0.15 sec)

mysql> desc clientmaster;

+----------+-------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+----------+-------------+------+-----+---------+-------+

| clientno | varchar(6) | YES | | NULL | |

| name | varchar(20) | YES | | NULL | |

| address1 | varchar(15) | YES | | NULL | |

| address2 | varchar(15) | YES | | NULL | |

| city | varchar(15) | YES | | NULL | |

| pincode | int(8) | YES | | NULL | |

| state | varchar(15) | YES | | NULL | |

| baldue | float(10,2) | YES | | NULL | |

+----------+-------------+------+-----+---------+-------+

8 rows in set (0.04 sec)

insert into clientmaster( clientno, name,city,pincode,state,baldue)values ('c00001','ivan bayross', 'mumbai',


400054, 'maharashtra', 15000);

Query OK, 1 row affected (0.47 sec)

mysql> insert into clientmaster( clientno, name,city,pincode,state,baldue)values ('c00002','mamata rane',


'madras', 780001, 'madras', 0);

Query OK, 1 row affected (0.02 sec)

mysql> insert into clientmaster( clientno, name,city,pincode,state,baldue)values ('c00003','chhaya bankar',


'mumbai', 400057, 'maharashtra', 5000);

Query OK, 1 row affected (0.03 sec)

mysql> insert into clientmaster( clientno, name,city,pincode,state,baldue)values ('c00004','ashwini joshi',


'banglore', 560001, 'karnataka', 0);
Query OK, 1 row affected (0.04 sec)

mysql> insert into clientmaster( clientno, name,city,pincode,state,baldue)values ('c00005','hansa doshi',


'mumbai', 400060, 'maharashtra', 2000);

Query OK, 1 row affected (0.39 sec)

mysql> insert into clientmaster( clientno, name,city,pincode,state,baldue)values ('c00006','deepak sharma',


'banglore', 560050, 'karnataka', 0);

Query OK, 1 row affected (0.03 sec)

select * from clientmaster;

+----------+---------------+----------+----------+----------+---------+-------------+----------+

| clientno | name | address1 | address2 | city | pincode | state | baldue |

+----------+---------------+----------+----------+----------+---------+-------------+----------+

| c00001 | ivan bayross | NULL | NULL | mumbai | 400054 | maharashtra | 15000.00 |

| c00001 | ivan bayross | NULL | NULL | mumbai | 400054 | maharashtra | 15000.00 |

| c00002 | mamata rane | NULL | NULL | madras | 780001 | madras | 0.00 |

| c00003 | chhaya bankar | NULL | NULL | mumbai | 400057 | maharashtra | 5000.00 |

| c00004 | ashwini joshi | NULL | NULL | banglore | 560001 | karnataka | 0.00 |

| c00005 | hansa doshi | NULL | NULL | mumbai | 400060 | maharashtra | 2000.00 |

| c00006 | deepak sharma | NULL | NULL | banglore | 560050 | karnataka | 0.00 |

+----------+---------------+----------+----------+----------+---------+-------------+----------+

7 rows in set (0.02 sec)

CHANGE A CITYNAME TO MANGLORE WHOSE PINCODE IS 560050.

mysql> update clientmaster set city='manglore' where pincode= 560050;

Query OK, 1 row affected (0.07 sec)


Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from clientmaster;

+----------+---------------+----------+----------+----------+---------+-------------+----------+

| clientno | name | address1 | address2 | city | pincode | state | baldue |

+----------+---------------+----------+----------+----------+---------+-------------+----------+

| c00001 | ivan bayross | NULL | NULL | mumbai | 400054 | maharashtra | 15000.00 |

| c00001 | ivan bayross | NULL | NULL | mumbai | 400054 | maharashtra | 15000.00 |

| c00002 | mamata rane | NULL | NULL | madras | 780001 | madras | 0.00 |

| c00003 | chhaya bankar | NULL | NULL | mumbai | 400057 | maharashtra | 5000.00 |

| c00004 | ashwini joshi | NULL | NULL | banglore | 560001 | karnataka | 0.00 |

| c00005 | hansa doshi | NULL | NULL | mumbai | 400060 | maharashtra | 2000.00 |

| c00006 | deepak sharma | NULL | NULL | manglore | 560050 | karnataka | 0.00 |

+----------+---------------+----------+----------+----------+---------+-------------+----------+

7 rows in set (0.00 sec)

DELETE THE RECORD OF IVAN BAYROSS

mysql> delete from clientmaster where name= 'ivan bayross';

Query OK, 2 rows affected (0.08 sec)


mysql> select * from clientmaster;

+----------+---------------+----------+----------+----------+---------+-------------+---------+

| clientno | name | address1 | address2 | city | pincode | state | baldue |

+----------+---------------+----------+----------+----------+---------+-------------+---------+

| c00002 | mamata rane | NULL | NULL | madras | 780001 | madras | 0.00 |

| c00003 | chhaya bankar | NULL | NULL | mumbai | 400057 | maharashtra | 5000.00 |

| c00004 | ashwini joshi | NULL | NULL | banglore | 560001 | karnataka | 0.00 |

| c00005 | hansa doshi | NULL | NULL | mumbai | 400060 | maharashtra | 2000.00 |

| c00006 | deepak sharma | NULL | NULL | manglore | 560050 | karnataka | 0.00 |

+----------+---------------+----------+----------+----------+---------+-------------+---------+

5 rows in set (0.00 sec)

mysql> commit;

Query OK, 0 rows affected (0.00 sec)

AjaraMahavidyalaya, Ajara

Department Of BCA

Assignment No:2 Date: Roll No : 203


Title: PERFROM
ADD COLUMN MOBILENUMBER TO TABLE EMPLOYEE
RENAME TABLE EMPLOUEE AS EMPLOYEE2
EMPTY ALL THE ROWS OF EMPLOYEE2 TABLE
DELETE TABLE EMPLOYEE2
Create user bca123, grant and revoke permissions to it for bca2
.
mysql> alter table employee add ( mobile int(10));

Query OK, 5 rows affected (0.61 sec)

Records: 5 Duplicates: 0 Warnings: 0

mysql> desc clientmaster;

+----------+-------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+----------+-------------+------+-----+---------+-------+

| clientno | varchar(6) | YES | | NULL | |

| name | varchar(20) | YES | | NULL | |

| address1 | varchar(15) | YES | | NULL | |

| address2 | varchar(15) | YES | | NULL | |

| city | varchar(15) | YES | | NULL | |

| pincode | int(8) | YES | | NULL | |

| state | varchar(15) | YES | | NULL | |

| baldue | float(10,2) | YES | | NULL | |

+----------+-------------+------+-----+---------+-------+

8 rows in set (0.00 sec)

mysql> alter table employee rename to employee2;

Query OK, 0 rows affected (0.07 sec)


mysql> show tables;

+----------------+

| Tables_in_bca2 |

+----------------+

| clientmaster |

| employee2 |

+----------------+

2 rows in set (0.00 sec)


mysql> truncate table employee2;

Query OK, 0 rows affected (0.06 sec)

mysql> select *from employee2;

Empty set (0.00 sec)

mysql> drop table employee2;

Query OK, 0 rows affected (0.04 sec)

mysql> select *from employee2;

ERROR 1146 (42S02): Table 'bca2.employee2' doesn't exist

mysql> create user bca123;

Query OK, 0 rows affected (0.32 sec)

Grant and revoke permissions

mysql> grant insert on bca2.* to bca123;

Query OK, 0 rows affected (0.03 sec)

mysql> grant delete on bca2.* to bca123;

Query OK, 0 rows affected (0.00 sec)

mysql> grant create on bca2.* to bca123;


Query OK, 0 rows affected (0.00 sec)

mysql> grant update on bca2.* to bca123;

Query OK, 0 rows affected (0.01 sec)

mysql> show grants for bca123;

+--------------------------------------------------+

| Grants for bca123@% |

+--------------------------------------------------+

| GRANT USAGE ON *.* TO 'bca123'@'%' |

| GRANT ALL PRIVILEGES ON `bca2`.* TO 'bca123'@'%' |

+--------------------------------------------------+

2 rows in set (0.00 sec)

mysql> grant alter on bca2.* to bca123;

Query OK, 0 rows affected (0.00 sec)

mysql> grant drop on bca2.* to bca123;

Query OK, 0 rows affected (0.00 sec)

mysql> grant index on bca2.* to bca123;

Query OK, 0 rows affected (0.01 sec)

mysql> revoke select on bca2.* from bca123;

Query OK, 0 rows affected (0.01 sec)


mysql> show grants for bca123;

+----------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------+

| Grants for bca123@%


|

+----------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------+

| GRANT USAGE ON *.* TO 'bca123'@'%'


|

| GRANT INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES,
LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER ON
`bca2`.* TO 'bca123'@'%' |

+----------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------+

2 rows in set (0.00 sec)

mysql> revoke delete on bca2.* from bca123;

Query OK, 0 rows affected (0.01 sec)

mysql> show grants for bca123;

+----------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------+

| Grants for bca123@%


|

+----------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------+

| GRANT USAGE ON *.* TO 'bca123'@'%'


|

| GRANT INSERT, UPDATE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK
TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER ON `bca2`.*
TO 'bca123'@'%' |

+----------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------+

2 rows in set (0.00 sec)


mysql> revoke all on bca2.* from bca123;

Query OK, 0 rows affected (0.00 sec)

mysql> show grants for bca123;

+------------------------------------+

| Grants for bca123@% |

+------------------------------------+

| GRANT USAGE ON *.* TO 'bca123'@'%' |

+------------------------------------+

1 row in set (0.01 sec)

AjaraMahavidyalaya, Ajara

Department Of BCA

Assignment No:3 Date: Roll No : 203


Title: Perform the following:
Simple Queries

Simple Queries with Aggregate functions

Queries with Aggregate functions (group by and having clause)


mysql> select * from clientmaster;

+----------+---------------+----------+----------+----------+---------+-------------+---------+

| clientno | name | address1 | address2 | city | pincode | state | baldue |

+----------+---------------+----------+----------+----------+---------+-------------+---------+

| c00002 | mamata rane | NULL | NULL | madras | 780001 | madras | 0.00 |

| c00003 | chhaya bankar | NULL | NULL | mumbai | 400057 | maharashtra | 5000.00 |

| c00004 | ashwini joshi | NULL | NULL | banglore | 560001 | karnataka | 0.00 |

| c00005 | hansa doshi | NULL | NULL | mumbai | 400060 | maharashtra | 2000.00 |

| c00006 | deepak sharma | NULL | NULL | manglore | 560050 | karnataka | 0.00 |

+----------+---------------+----------+----------+----------+---------+-------------+---------+

5 rows in set (0.00 sec)

mysql> select *from acc_master;

+--------+-----------+------------+-----------+

| acc_n0 | name | city | balance |

+--------+-----------+------------+-----------+

| 1001 | archana | ajara | 10000.00 |

| 1002 | sania | uttur | 20000.00 |

| 1003 | sameer | paroli | 25000.00 |

| 1004 | varad | polgaon | 50000.00 |

| 1005 | swanandi | inchnal | 60000.00 |

| 1006 | om | ajara | 100000.00 |


| 1007 | raj | ajara | 100000.00 |

| 1008 | aarav | gadhingla | 300000.00 |

| 1009 | aishwarya | gadhingla | 300000.00 |

| 1010 | bhakti | ajara | 30000.00 |

+--------+-----------+------------+-----------+

10 rows in set (0.06 sec)


mysql> select name, city, state from clientmaster;

+---------------+----------+-------------+

| name | city | state |

+---------------+----------+-------------+

| mamata rane | madras | madras |

| chhaya bankar | mumbai | maharashtra |

| ashwini joshi | banglore | karnataka |

| hansa doshi | mumbai | maharashtra |

| deepak sharma | manglore | karnataka |

+---------------+----------+-------------+

5 rows in set (0.00 sec)

mysql> update clientmaster set city= 'banglore' where clientno= 'c00005';

Query OK, 1 row affected (0.06 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> update clientmaster set baldue= '1000' where clientno= 'c00001';

Query OK, 1 row affected (0.33 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> update clientmaster set state='tamilnadu' where city= 'madras';


Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> delete from clientmaster where state='tamilnadu';

Query OK, 1 row affected (0.03 sec)

mysql> select * from clientmaster;

+----------+---------------+----------+----------+----------+---------+-------------+---------+

| clientno | name | address1 | address2 | city | pincode | state | baldue |

+----------+---------------+----------+----------+----------+---------+-------------+---------+

| c00003 | chhaya bankar | NULL | NULL | mumbai | 400057 | maharashtra | 5000.00 |

| c00004 | ashwini joshi | NULL | NULL | banglore | 560001 | karnataka | 0.00 |

| c00005 | hansa doshi | NULL | NULL | banglore | 400060 | maharashtra | 2000.00 |

| c00006 | deepak sharma | NULL | NULL | manglore | 560050 | karnataka | 0.00 |

| c00001 | ivan bayross | NULL | NULL | mumbai | 400054 | maharashtra | 1000.00 |

+----------+---------------+----------+----------+----------+---------+-------------+---------+

5 rows in set (0.00 sec)

mysql> select avg(balance) " AVG BAL" from acc_master;

+--------------+

| AVG BAL |

+--------------+

| 99500.000000 |

+--------------+

1 row in set, 1 warning (0.06 sec)

mysql> select min(balance) " MIN BAL" from acc_master;

+----------+

| MIN BAL |

+----------+

| 10000.00 |
+----------+

1 row in set, 1 warning (0.11 sec)

mysql> select max(balance) " Max BAL" from acc_master;

+-----------+

| Max BAL |

+-----------+

| 300000.00 |

+-----------+

1 row in set, 1 warning (0.01 sec)

mysql> select sum(balance) " TOTAL BAL" from acc_master;

+-----------+

| TOTAL BAL |

+-----------+

| 995000.00 |

+-----------+

1 row in set, 1 warning (0.01 sec)

mysql> select city, count(acc_n0) "NO OF ACCOUNTS" from acc_master group by city;

+------------+----------------+

| city | NO OF ACCOUNTS |

+------------+----------------+

| ajara | 4|

| gadhingla | 2|

| inchnal | 1|
| paroli | 1|

| polgaon | 1|
| uttur | 1|

+------------+----------------+

6 rows in set (0.08 sec)

mysql> select city,name,balance from acc_master order by balance;

+------------+-----------+-----------+

| city | name | balance |

+------------+-----------+-----------+

| ajara | archana | 10000.00 |

| uttur | sania | 20000.00 |

| paroli | sameer | 25000.00 |

| ajara | bhakti | 30000.00 |

| polgaon | varad | 50000.00 |

| inchnal | swanandi | 60000.00 |

| ajara | raj | 100000.00 |

| ajara | om | 100000.00 |

| gadhingla | aarav | 300000.00 |

| gadhingla | aishwarya | 300000.00 |

+------------+-----------+-----------+

10 rows in set (0.08 sec)

mysql> select city, sum(balance) as TOTAL from acc_master group by city;

+------------+-----------+

| city | TOTAL |

+------------+-----------+

| ajara | 240000.00 |

| gadhingla | 600000.00 |

| inchnal | 60000.00 |
| paroli | 25000.00 |

| polgaon | 50000.00 |

| uttur | 20000.00 |

+------------+-----------+

6 rows in set (0.50 sec)


mysql> select city, min(balance) as MINBAL from acc_master group by city;

+------------+-----------+

| city | MINBAL |

+------------+-----------+

| ajara | 10000.00 |

| gadhingla | 300000.00 |

| inchnal | 60000.00 |

| paroli | 25000.00 |

| polgaon | 50000.00 |

| uttur | 20000.00 |

+------------+-----------+

6 rows in set (0.00 sec)

mysql> select city, sum(balance)as total from acc_master group by city having sum(balance)>100000;

+------------+-----------+

| city | total |

+------------+-----------+

| ajara | 240000.00 |

| gadhingla | 600000.00 |

+------------+-----------+

2 rows in set (0.01 sec)


mysql> select city, max(balance) as MAXBAL from acc_master group by city having max(balance)<50000;

+---------+----------+
| city | MAXBAL |

+---------+----------+

| paroli | 25000.00 |

| uttur | 20000.00 |

+---------+----------+

2 rows in set (0.01 sec)


mysql> select city, min(balance) as MINBAL from acc_master group by city having min(balance)>10000;

+------------+-----------+

| city | MINBAL |

+------------+-----------+

| gadhingla | 300000.00 |

| inchnal | 60000.00 |

| paroli | 25000.00 |

| polgaon | 50000.00 |

| uttur | 20000.00 |

+------------+-----------+

5 rows in set (0.02 sec)

AjaraMahavidyalaya, Ajara

Department Of BCA

Assignment No: 4 Date: Roll No : 203


Title: Perform

String functions

Maths functions

Date functions
mysql> select lower('Ajara') from dual;
+----------------+
| lower('Ajara') |
+----------------+
| ajara |
+----------------+
1 row in set (0.00 sec)
mysql> select upper('Ajara') from dual;
+----------------+
| upper('Ajara') |
+----------------+
| AJARA |
+----------------+
1 row in set (0.00 sec)
mysql> select length('Ajara')from dual;
+-----------------+
| length('Ajara') |
+-----------------+
| 5|
+-----------------+
1 row in set (0.00 sec)

mysql> select ltrim ('ajara''a') from dual;


+---------------------+
| ltrim ('ajara''a') |
+---------------------+
| ajara'a |
+---------------------+
row in set (0.00 sec)

mysql> select rtrim('ajara' 'a') from dual;


+--------------------+
| rtrim('ajara' 'a') |
+--------------------+
| ajaraa |
+--------------------+
1 row in set (0.00 sec)
MATH FUNCTIONS IN MYSQL
mysql> select pow(3,2);

+----------+

| pow(3,2) |

+----------+

| 9|

+----------+

1 row in set (0.00 sec)

mysql> select abs(-14);

+----------+

| abs(-14) |

+----------+

| 14 |

+----------+

1 row in set (0.00 sec)

mysql> select ceil(14.6);

+------------+

| ceil(14.6) |

+------------+

| 15 |

+------------+

1 row in set (0.00 sec)

mysql> select floor(14.6);

+-------------+

| floor(14.6) |
+-------------+

| 14 |

+-------------+

1 row in set (0.00 sec)

mysql> select mod (25, 3);

+-------------+

| mod (25, 3) |

+-------------+

| 1|

+-------------+

1 row in set (0.00 sec)

mysql> select sqrt (25);

+-----------+

| sqrt (25) |

+-----------+

| 5|

+-----------+

1 row in set (0.00 sec)

AjaraMahavidyalaya, Ajara

Department Of BCA

Assignment No:5 Date: Roll No : 203


Title: Perform various joins in mysql
mysql> select * from department;

+--------+----------+

| deptid | deptname |

+--------+----------+

| 5001 | informat |

| 5002 | human re |

| 5003 | marketin |

| 5004 | administ |

| 5005 | finance |

+--------+----------+

5 rows in set (0.01 sec)

mysql> select * from employee;

+-------+----------+--------+

| empid | emp_name | deptid |

+-------+----------+--------+

| 1001 | anita | 5001 |

| 1002 | sunita | 5001 |

| 1003 | suresh | 5002 |

| 1004 | ramesh | 5003 |

| 1005 | satish | 5004 |

| 1006 | saina | 5004 |

| 1007 | priyali | 5005 |

| 1008 | anil | 5003 |

| 1009 | manali | 5002 |


| 1010 | prayag | 5002 |

+-------+----------+--------+

10 rows in set (0.00 sec)

mysql> select employee.empid, employee.emp_name, department.deptname from employee inner join


department on employee.deptid= department.deptid;

+-------+----------+----------+

| empid | emp_name | deptname |

+-------+----------+----------+

| 1001 | anita | informat |

| 1002 | sunita | informat |

| 1003 | suresh | human re |

| 1004 | ramesh | marketin |

| 1005 | satish | administ |

| 1006 | saina | administ |

| 1007 | priyali | finance |

| 1008 | anil | marketin |

| 1009 | manali | human re |

| 1010 | prayag | human re |

+-------+----------+----------+

10 rows in set (0.02 sec)

sql> insert into employee(empid, emp_name) values ( 1011, 'bhakti');

Query OK, 1 row affected (0.03 sec)

mysql> insert into employee(empid, emp_name) values ( 1012, 'shakti');

Query OK, 1 row affected (0.03 sec)

mysql> select employee.empid, employee.emp_name, department.deptname from employee left join


department on employee.deptid= department.deptid;
+-------+----------+----------+

| empid | emp_name | deptname |

+-------+----------+----------+

| 1001 | anita | informat |

| 1002 | sunita | informat |

| 1003 | suresh | human re |

| 1004 | ramesh | marketin |

| 1005 | satish | administ |

| 1006 | saina | administ |

| 1007 | priyali | finance |

| 1008 | anil | marketin |

| 1009 | manali | human re |

| 1010 | prayag | human re |

| 1011 | bhakti | NULL |

| 1012 | shakti | NULL |

+-------+----------+----------+

mysql> select employee.empid, employee.emp_name, department.deptname from employee right join


department on employee.deptid= department.deptid;

+-------+----------+----------+

| empid | emp_name | deptname |

+-------+----------+----------+

| 1001 | anita | informat |

| 1002 | sunita | informat |

| 1003 | suresh | human re |

| 1009 | manali | human re |

| 1010 | prayag | human re |

| 1004 | ramesh | marketin |


| 1008 | anil | marketin |

| 1005 | satish | administ |

| 1006 | saina | administ |

| 1007 | priyali | finance |

| 1013 | prayag | NULL |

| 1014 | prachi | NULL |

+-------+----------+----------+

12 rows in set (0.00 sec)

AjaraMahavidyalaya, Ajara

Department Of BCA

Assignment No:6 Date: Roll No : 203


Title: SUBQUERIES WITH IN AND EXIST CLAUSE
mysql> select distinct(e. emp_name) from employee e, department d where d.deptname in (e.deptid=d.deptid);

+----------+

| emp_name |

+----------+

| anita |

| sunita |

| suresh |

| ramesh |

| satish |

| saina |

| priyali |

| anil |

| manali |

| prayag |

| prachi |

+----------+

11 rows in set, 70 warnings (0.11 sec)

HAVE TO COMPLETE

mysql> select *from employee;

+--------+-----------+---------+------------+---------+
| emp_id | emp_name | emp_age | city | income |

+--------+-----------+---------+------------+---------+

| 101 | peter | 32 | newyork | 200000 |

| 102 | mark | 32 | california | 300000 |

| 103 | donald | 40 | Arizona | 1000000 |

| 104 | obama | 35 | florida | 5000000 |

| 105 | linklon | 32 | georgia | 250000 |

| 106 | kane | 45 | alaska | 450000 |

| 107 | adam | 35 | california | 500000 |

| 108 | macculam | 40 | florida | 35000 |

| 109 | brayan | 40 | alaska | 40000 |

| 110 | stefen | 40 | arizona | 600000 |

| 111 | alexander | 45 | california | 70000 |

+--------+-----------+---------+------------+---------+

11 rows in set (0.00 sec)


AjaraMahavidyalaya, Ajara

Department Of BCA

Assignment No:7 Date: Roll No : 203


Title: SUBQUERIES WITH ANY AND ALL CLAUSES

mysql> select emp_id, emp_name from employee where emp_id> any(select emp_id from department);

+--------+-----------+

| emp_id | emp_name |

+--------+-----------+

| 102 | mark |

| 103 | donald |

| 104 | obama |

| 105 | linklon |

| 106 | kane |

| 107 | adam |

| 108 | macculam |

| 109 | brayan |

| 110 | stefen |

| 111 | alexander |

+--------+-----------+

10 rows in set (0.09 sec)

mysql> select emp_id, emp_name from employee where emp_id> all(select emp_id from department);

Empty set (0.07 sec)


AjaraMahavidyalaya, Ajara

Department Of BCA

Assignment No: 8 Date: Roll No : 203


Title:. CREATE VIEW, UPDATE IT AND THEN DELETE IT.

.
mysql> select *from employee;

+--------+-----------+---------+------------+---------+

| emp_id | emp_name | emp_age | city | income |

+--------+-----------+---------+------------+---------+

| 101 | peter | 32 | newyork | 200000 |

| 102 | mark | 32 | california | 300000 |

| 103 | donald | 40 | Arizona | 1000000 |

| 104 | obama | 35 | florida | 5000000 |

| 105 | linklon | 32 | georgia | 250000 |

| 106 | kane | 45 | alaska | 450000 |

| 107 | adam | 35 | california | 500000 |

| 108 | macculam | 40 | florida | 35000 |

| 109 | brayan | 40 | alaska | 40000 |

| 110 | stefen | 40 | arizona | 600000 |

| 111 | alexander | 45 | california | 70000 |

+--------+-----------+---------+------------+---------+

11 rows in set (0.00 sec)

mysql> create view employee1 as select emp_id, emp_name from employee where emp_age>40;

Query OK, 0 rows affected (0.19 sec)


mysql> select * from employee1;

+--------+-----------+

| emp_id | emp_name |

+--------+-----------+

| 106 | kane |

| 111 | alexander |

+--------+-----------+

2 rows in set (0.16 sec)

mysql> alter view employee1 as select emp_id, emp_name from employee where emp_age<40;

Query OK, 0 rows affected (0.06 sec)

mysql> select * from employee1;

+--------+----------+

| emp_id | emp_name |

+--------+----------+

| 101 | peter |

| 102 | mark |

| 104 | obama |

| 105 | linklon |

| 107 | adam |

+--------+----------+

5 rows in set (0.01 sec)

mysql> drop view employee1;

Query OK, 0 rows affected (0.03 sec)


AjaraMahavidyalaya, Ajara

Department Of BCA

Assignment No: 9 Date: Roll No : 203


Title:. Develope a stored procedure that creates the list of names of all the students in the student
table in the sample database.
mysql> select * from stydent;

+------+---------+--------+

| id | name | class |

+------+---------+--------+

| 1 | deepa | M.C.A. |

| 2 | deepak | B.C.A. |

| 3 | seeta | M.C.A. |

| 4 | rahul | B.C.A. |

| 5 | ratan | M.C.A. |

| 6 | sanjeev | B.C.A. |

| 7 | diyva | B.C.A. |

| 8 | reena | M.C.A. |

+------+---------+--------+

8 rows in set (0.00 sec)

mysql> commit;

Query OK, 0 rows affected (0.00 sec)

mysql> delimiter $$

mysql> create procedure list_nm( inout name_list varchar(40000))

->

-> begin
->

-> declare is_done integer default 0;

->

-> declare s_nm varchar(100) default "";

->

-> declare s_cursor cursor for

->

-> select name from stydent;

-> declare continue handler for not found set is_done=1;

->

-> open s_cursor;

->

-> get_list : loop

->

-> fetch s_cursor into s_nm;

->

-> if is_done=1 then

->

-> leave get_list;

->

-> end if;

->

-> set name_list= concat(s_nm, ";",name_list);

->

-> end loop get_list;

->

-> close s_cursor;


->

-> end $$

Query OK, 0 rows affected (0.00 sec)

mysql> set @name_list= " ";

-> $$

Query OK, 0 rows affected (0.00 sec)

mysql> call list_nm(@name_list);

-> $$

Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> select @name_list;

-> $$

+------------------------------------------------------+

| @name_list |

+------------------------------------------------------+

| reena;diyva;sanjeev;ratan;rahul;seeta;deepak;deepa; |

+------------------------------------------------------+

1 row in set (0.00 sec)

AjaraMahavidyalaya, Ajara

Department Of BCA

Assignment No: 10 Date: Roll No : 203


Title:. Develope a stored trigger that will add constraint on on table employee while inserting data.
null,working_datte date, working_hours varchar(10));

Query OK, 0 rows affected (0.01 sec)

mysql> insert into employee values(01, 'rohan', 'scientist', '2020-10-04',12); Query OK, 1 row affected (0.01 sec)

mysql> insert into employee values(02, 'sujal', 'engineer', '2020-10-04',10); Query OK, 1 row affected (0.01 sec)

mysql> insert into employee values(03, 'robin', 'actor', '2020-10-04',13);

Query OK, 1 row affected (0.00 sec)

mysql> insert into employee values(04, 'prasad', 'doctor', '2020-10-04',14);

Query OK, 1 row affected (0.01 sec)

mysql> insert into employee values(05, 'businessman', 'teacher', '2020-10-04',12);

Query OK, 1 row affected (0.01 sec)

mysql> insert into employee values(05, 'radhika', 'businessman', '2020-10-04',11);

ERROR 1062 (23000): Duplicate entry '5' for key 'PRIMARY'

mysql> update employee set name='radhika' where emp_id=05;

Query OK, 1 row affected (0.00 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> insert into employee values(06, 'rakesh', 'businessman', '2020-10-04',11);

Query OK, 1 row affected (0.00 sec)


mysql> delimiter $$

mysql> create trigger before_insert_on_employeeworkinghours

->

-> before insert on employee for each row

->

-> begin

->

-> if new.working_hours<0 then set new.working_hours=0;

->

-> end if;

->

-> end

-> $$

Query OK, 0 rows affected (0.00 sec)

mysql> insert into employee values(07, 'raja', 'watchman', '2020-10-04',-1);

-> $$

Query OK, 1 row affected (0.01 sec)

mysql> select *from employee;

-> $$

+--------+---------+-------------+---------------+---------------+

| emp_id | name | occupation | working_datte | working_hours |

+--------+---------+-------------+---------------+---------------+

| 1 | rohan | scientist | 2020-10-04 | 12 |


| 2 | sujal | engineer | 2020-10-04 | 10 |

| 3 | robin | actor | 2020-10-04 | 13 |

| 4 | prasad | doctor | 2020-10-04 | 14 |

| 5 | radhika | teacher | 2020-10-04 | 12 |

| 6 | rakesh | businessman | 2020-10-04 | 11 |

| 7 | raja | watchman | 2020-10-04 | 0 |

+--------+---------+-------------+---------------+---------------+

7 rows in set (0.00 sec)

mysql> show triggers;

-> $$

+---------------------------------------+--------+----------
+------------------------------------------------------------------------------------------+--------+---------+----------+----------------
+----------------------+----------------------+--------------------+

| Trigger | Event | Table | Statement | Timing |


Created | sql_mode | Definer | character_set_client | collation_connection | Database Collation |

+---------------------------------------+--------+----------
+------------------------------------------------------------------------------------------+--------+---------+----------+----------------
+----------------------+----------------------+--------------------+

| before_insert_on_employeeworkinghours | INSERT | employee | begin

if new.working_hours<0 then set new.working_hours=0;

end if;

end | BEFORE | NULL | | root@localhost | utf8 | utf8_general_ci | latin1_swedish_ci |

+---------------------------------------+--------+----------
+------------------------------------------------------------------------------------------+--------+---------+----------+----------------
+----------------------+----------------------+--------------------+

1 row in set (0.00 sec)

You might also like