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

Informatics Practices ass5

Dnndndndndn

Uploaded by

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

Informatics Practices ass5

Dnndndndndn

Uploaded by

narangbhanu2408
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Informatics Practices

Akavira kesar XII-B


Assignment 5
mysql> create database Akavira12;
Query OK, 1 row affected (0.08 sec)

mysql> use AKavira12;


Database changed

Q1.
mysql> create table Stock(Itemno char(3) Primary key, Itemname varchar(50) not
null, Brand varchar(10), Qty int, Unitprice float(5,2), Stockdate date);
Query OK, 0 rows affected, 1 warning (0.13 sec)

mysql> insert into stock values('S05', 'Ball pen 0.5', 'Luxor', 100, 16,
'2021-03-31');
Query OK, 1 row affected (0.14 sec)

mysql> insert into stock values('S03', 'Ball pen 0.25', 'Reynolds', 150,
20.05, '2022-01-01');
Query OK, 1 row affected (0.02 sec)

mysql> insert into stock values('S02', 'Gell pen premium', 'Luxor', 125,
14.42, '2022-02-14');
Query OK, 1 row affected (0.01 sec)

mysql> insert into stock values('S06', 'Gell pen clasic', 'Pentel', 200,
22.75, '2022-01-09');
Query OK, 1 row affected (0.01 sec)

mysql> insert into stock values('S01', 'Eraser small', 'null', 210, null,
null);
Query OK, 1 row affected (0.01 sec)

mysql> insert into stock values('S04', 'Eraser big', 'Apsara', 60, 10, '2020-
12-12');
Query OK, 1 row affected (0.02 sec)

mysql> insert into stock values('S09', 'Sharpner clasic', 'Apsara', 160, 8,


'2021-01-23');
Query OK, 1 row affected (0.01 sec)
mysql> desc stock;
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| Itemno | char(3) | NO | PRI | NULL | |
| Itemname | varchar(50) | NO | | NULL | |
| Brand | varchar(10) | YES | | NULL | |
| Qty | int | YES | | NULL | |
| Unitprice | float(5,2) | YES | | NULL | |
| Stockdate | date | YES | | NULL | |
+-----------+-------------+------+-----+---------+-------+
6 rows in set (0.20 sec)

mysql> select * from stock;


+--------+------------------+----------+------+-----------+------------+
| Itemno | Itemname | Brand | Qty | Unitprice | Stockdate |
+--------+------------------+----------+------+-----------+------------+
| S01 | Eraser small | null | 210 | NULL | NULL |
| S02 | Gell pen premium | Luxor | 125 | 14.42 | 2022-02-14 |
| S03 | Ball pen 0.25 | Reynolds | 150 | 20.05 | 2022-01-01 |
| S04 | Eraser big | Apsara | 60 | 10.00 | 2020-12-12 |
| S05 | Ball pen 0.5 | Luxor | 100 | 16.00 | 2021-03-31 |
| S06 | Gell pen clasic | Pentel | 200 | 22.75 | 2022-01-09 |
| S09 | Sharpner clasic | Apsara | 160 | 8.00 | 2021-01-23 |
+--------+------------------+----------+------+-----------+------------+
7 rows in set (0.05 sec)

mysql> select * from stock order by stockdate;


+--------+------------------+----------+------+-----------+------------+
| Itemno | Itemname | Brand | Qty | Unitprice | Stockdate |
+--------+------------------+----------+------+-----------+------------+
| S01 | Eraser small | null | 210 | NULL | NULL |
| S04 | Eraser big | Apsara | 60 | 10.00 | 2020-12-12 |
| S09 | Sharpner clasic | Apsara | 160 | 8.00 | 2021-01-23 |
| S05 | Ball pen 0.5 | Luxor | 100 | 16.00 | 2021-03-31 |
| S03 | Ball pen 0.25 | Reynolds | 150 | 20.05 | 2022-01-01 |
| S06 | Gell pen clasic | Pentel | 200 | 22.75 | 2022-01-09 |
| S02 | Gell pen premium | Luxor | 125 | 14.42 | 2022-02-14 |
+--------+------------------+----------+------+-----------+------------+
7 rows in set (0.01 sec)

mysql> select * from stock where qty>100;


+--------+------------------+----------+------+-----------+------------+
| Itemno | Itemname | Brand | Qty | Unitprice | Stockdate |
+--------+------------------+----------+------+-----------+------------+
| S01 | Eraser small | null | 210 | NULL | NULL |
| S02 | Gell pen premium | Luxor | 125 | 14.42 | 2022-02-14 |
| S03 | Ball pen 0.25 | Reynolds | 150 | 20.05 | 2022-01-01 |
| S06 | Gell pen clasic | Pentel | 200 | 22.75 | 2022-01-09 |
| S09 | Sharpner clasic | Apsara | 160 | 8.00 | 2021-01-23 |
+--------+------------------+----------+------+-----------+------------+
5 rows in set (0.01 sec)

mysql> select Itemno, Itemname, Unitprice+5 as Newunitprice from stock;


+--------+------------------+--------------+
| Itemno | Itemname | Newunitprice |
+--------+------------------+--------------+
| S01 | Eraser small | NULL |
| S02 | Gell pen premium | 19.42 |
| S03 | Ball pen 0.25 | 25.05 |
| S04 | Eraser big | 15.00 |
| S05 | Ball pen 0.5 | 21.00 |
| S06 | Gell pen clasic | 27.75 |
| S09 | Sharpner clasic | 13.00 |
+--------+------------------+--------------+
7 rows in set (0.18 sec)

mysql> select Itemname, Qty*Unitprice as Totalvalue from stock;


+------------------+------------+
| Itemname | Totalvalue |
+------------------+------------+
| Eraser small | NULL |
| Gell pen premium | 1802.50 |
| Ball pen 0.25 | 3007.50 |
| Eraser big | 600.00 |
| Ball pen 0.5 | 1600.00 |
| Gell pen clasic | 4550.00 |
| Sharpner clasic | 1280.00 |
+------------------+------------+
7 rows in set (0.05 sec)

mysql> select itemname, qty from stock where itemname like '%Pen%';
+------------------+------+
| itemname | qty |
+------------------+------+
| Gell pen premium | 125 |
| Ball pen 0.25 | 150 |
| Ball pen 0.5 | 100 |
| Gell pen clasic | 200 |
+------------------+------+
4 rows in set (0.01 sec)
mysql> select * from stock where unitprice between 15 and 20;
+--------+--------------+-------+------+-----------+------------+
| Itemno | Itemname | Brand | Qty | Unitprice | Stockdate |
+--------+--------------+-------+------+-----------+------------+
| S05 | Ball pen 0.5 | Luxor | 100 | 16.00 | 2021-03-31 |
+--------+--------------+-------+------+-----------+------------+
1 row in set (0.12 sec)

mysql> select itemno, itemname from stock where itemno='S01' or itemno='S03';


+--------+---------------+
| itemno | itemname |
+--------+---------------+
| S01 | Eraser small |
| S03 | Ball pen 0.25 |
+--------+---------------+
2 rows in set (0.13 sec)

mysql> select * from stock where stockdate is Null;


+--------+--------------+-------+------+-----------+-----------+
| Itemno | Itemname | Brand | Qty | Unitprice | Stockdate |
+--------+--------------+-------+------+-----------+-----------+
| S01 | Eraser small | null | 210 | NULL | NULL |
+--------+--------------+-------+------+-----------+-----------+
1 row in set (0.08 sec)
mysql> select * from stock where stockdate between '2021-01-01' and '2021-12-
31';
+--------+-----------------+--------+------+-----------+------------+
| Itemno | Itemname | Brand | Qty | Unitprice | Stockdate |
+--------+-----------------+--------+------+-----------+------------+
| S05 | Ball pen 0.5 | Luxor | 100 | 16.00 | 2021-03-31 |
| S09 | Sharpner clasic | Apsara | 160 | 8.00 | 2021-01-23 |
+--------+-----------------+--------+------+-----------+------------+
2 rows in set (0.08 sec)

mysql> select distinct(Brand) from stock;


+----------+
| Brand |
+----------+
| null |
| Luxor |
| Reynolds |
| Apsara |
| Pentel |
+----------+
5 rows in set (0.04 sec)

mysql> delete from stock where itemno= 'S01';


Query OK, 1 row affected (0.14 sec)

mysql> delete from stock;


Query OK, 6 rows affected (0.02 sec)

Q2.
mysql> create table Employee(Empno char(4) Primary key, Ename varchar(20), Job
varchar(15), Hiredate date, Sal int, Comm int, Deptno int);
Query OK, 0 rows affected (0.27 sec)

mysql> insert into employee values(8369, 'Smith', 'Clerk', '1990-12-18', 8000,


null, 20);
Query OK, 1 row affected (0.07 sec)

mysql> insert into employee values(8499, 'Anya', 'Salesman', '1991-02-20',


16000, 500, 30);
Query OK, 1 row affected (0.01 sec)

mysql> insert into employee values(8521, 'Mahadeven', 'Salesman', '1991-02-


22', 10000, 300, 30);
Query OK, 1 row affected (0.09 sec)

mysql> insert into employee values(8566, 'Momin', 'Manager', '1991-04-02',


25000, null, 10);
Query OK, 1 row affected (0.08 sec)

mysql> insert into employee values(8654, 'Bina', 'Analyst', '1992-12-09',


30000, null, 20);
Query OK, 1 row affected (0.15 sec)

mysql> insert into employee values(8698, 'Shivansh', 'President', '1991-11-


18', 50000, null, 10);
Query OK, 1 row affected (0.12 sec)

mysql> insert into employee values(8882, 'Scott', 'Salesman', '1991-05-01',


12000, 1200, 30);
Query OK, 1 row affected (0.01 sec)
mysql> alter table employee modify ename varchar(20) not null;
Query OK, 0 rows affected (0.33 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> Alter table employee modify ename varchar(25);


Query OK, 0 rows affected (0.63 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table employee add Bonues float(5,2);


Query OK, 0 rows affected, 1 warning (0.28 sec)
Records: 0 Duplicates: 0 Warnings: 1

mysql> Update employee set Bonues = 700;


Query OK, 7 rows affected (0.12 sec)
Rows matched: 7 Changed: 7 Warnings: 0

mysql> select empno, ename from employee;


+-------+-----------+
| empno | ename |
+-------+-----------+
| 8369 | Smith |
| 8499 | Anya |
| 8521 | Mahadeven |
| 8566 | Momin |
| 8654 | Bina |
| 8698 | Shivansh |
| 8882 | Scott |
+-------+-----------+
7 rows in set (0.03 sec)

mysql> select ename, sal, deptno from employee where comm is null;
+----------+-------+--------+
| ename | sal | deptno |
+----------+-------+--------+
| Smith | 8000 | 20 |
| Momin | 25000 | 10 |
| Bina | 30000 | 20 |
| Shivansh | 50000 | 10 |
+----------+-------+--------+
4 rows in set (0.02 sec)

mysql> select empno, ename, sal, sal*12 as Annualsal from employee;


+-------+-----------+-------+-----------+
| empno | ename | sal | Annualsal |
+-------+-----------+-------+-----------+
| 8369 | Smith | 8000 | 96000 |
| 8499 | Anya | 16000 | 192000 |
| 8521 | Mahadeven | 10000 | 120000 |
| 8566 | Momin | 25000 | 300000 |
| 8654 | Bina | 30000 | 360000 |
| 8698 | Shivansh | 50000 | 600000 |
| 8882 | Scott | 12000 | 144000 |
+-------+-----------+-------+-----------+
7 rows in set (0.19 sec)

mysql> select ename, sal, comm from employee where comm is not null;
+-----------+-------+------+
| ename | sal | comm |
+-----------+-------+------+
| Anya | 16000 | 500 |
| Mahadeven | 10000 | 300 |
| Scott | 12000 | 1200 |
+-----------+-------+------+
3 rows in set (0.03 sec)

mysql> select distinct(deptno) from employee;


+--------+
| deptno |
+--------+
| 20 |
| 30 |
| 10 |
+--------+
3 rows in set (0.05 sec)

mysql> select * from employee where sal between 20000 and 50000;
+-------+----------+-----------+------------+-------+------+--------+--------+
| Empno | ename | Job | Hiredate | Sal | Comm | Deptno | Bonues |
+-------+----------+-----------+------------+-------+------+--------+--------+
| 8566 | Momin | Manager | 1991-04-02 | 25000 | NULL | 10 | 700.00 |
| 8654 | Bina | Analyst | 1992-12-09 | 30000 | NULL | 20 | 700.00 |
| 8698 | Shivansh | President | 1991-11-18 | 50000 | NULL | 10 | 700.00 |
+-------+----------+-----------+------------+-------+------+--------+--------+
3 rows in set (0.05 sec)

mysql> select job from employee where job like '%Man%';


+----------+
| job |
+----------+
| Salesman |
| Salesman |
| Manager |
| Salesman |
+----------+
4 rows in set (0.01 sec)

mysql> Update employee set sal = sal+sal*0.1;


Query OK, 7 rows affected (0.10 sec)
Rows matched: 7 Changed: 7 Warnings: 0

mysql> Update employee set sal = 10000, comm = 200 where empno=8369;
Query OK, 1 row affected (0.09 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> Update employee set ename = 'Aanya' where empno=8499;


Query OK, 1 row affected (0.19 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from employee where ename like '____';


+-------+-------+---------+------------+-------+------+--------+--------+
| Empno | ename | Job | Hiredate | Sal | Comm | Deptno | Bonues |
+-------+-------+---------+------------+-------+------+--------+--------+
| 8654 | Bina | Analyst | 1992-12-09 | 33000 | NULL | 20 | 700.00 |
+-------+-------+---------+------------+-------+------+--------+--------+
1 row in set (0.03 sec)

mysql> select * from employee where ename like '%N';


+-------+-----------+----------+------------+-------+------+--------+--------+
| Empno | ename | Job | Hiredate | Sal | Comm | Deptno | Bonues |
+-------+-----------+----------+------------+-------+------+--------+--------+
| 8521 | Mahadeven | Salesman | 1991-02-22 | 11000 | 300 | 30 | 700.00 |
| 8566 | Momin | Manager | 1991-04-02 | 27500 | NULL | 10 | 700.00 |
+-------+-----------+----------+------------+-------+------+--------+--------+
2 rows in set (0.00 sec)

mysql> Delete from employee where deptno = 10 or deptno = 20;


Query OK, 4 rows affected (0.10 sec)

mysql> drop table employee;


Query OK, 0 rows affected (0.14 sec)

You might also like