0% found this document useful (0 votes)
165 views13 pages

Mysql Practicals

The document shows SQL commands and queries being run on a MySQL database. It creates databases and tables, inserts and selects data, and uses various functions. Key points include: 1) It creates a database called "meangerie" and a table called "handbags" to store product data. 2) Various SELECT queries are run to retrieve, filter, and aggregate data from the handbags table. 3) Functions are used to manipulate and extract information from the data, such as upper(), length(), concat(), round(), and avg().

Uploaded by

Ankit Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
165 views13 pages

Mysql Practicals

The document shows SQL commands and queries being run on a MySQL database. It creates databases and tables, inserts and selects data, and uses various functions. Key points include: 1) It creates a database called "meangerie" and a table called "handbags" to store product data. 2) Various SELECT queries are run to retrieve, filter, and aggregate data from the handbags table. 3) Functions are used to manipulate and extract information from the data, such as upper(), length(), concat(), round(), and avg().

Uploaded by

Ankit Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

MYsql

practicals

1
mysql> Show databases;
+--------------------+
| Database
|
+--------------------+
| information_schema |
| mysql
|
| performance_schema |
| test
|
+--------------------+
4 rows in set (0.00 sec)
2
mysql> Create database meangerie;
Query OK, 1 row affected (0.00 sec)

mysql> Create table handbags( productid varchar(5), productname char(20),


producttype char(30), productcost decimal);
Query OK, 0 rows affected (0.19 sec)
4
mysql> Select char(70,65,67,69);
+-------------------+
| char(70,65,67,69) |
+-------------------+
| FACE
|
+-------------------+
1 row in set (0.04 sec)

mysql> desc handbags;

+-------------+---------------+------+-----+---------+-------+
| Field
| Type
| Null | Key | Default | Extra |
+-------------+---------------+------+-----+---------+-------+
| productid | varchar(5) | YES |
| NULL |
|
| pname
| varchar(20) | YES |
| NULL |
|
| producttype | char(30)
| YES |
| NULL |
|
| productcost | decimal(10,0) | YES |
| NULL |
|
+-------------+---------------+------+-----+---------+-------+

mysql> show tables;


+---------------------+
| Tables_in_meangerie |
+---------------------+
| handbags
|
+---------------------+
1 row in set (0.00 sec)
7
mysql> Alter table handbags change productname pname varchar(20);
Query OK, 0 rows affected (0.39 sec)
Records: 0 Duplicates: 0 Warnings: 0

8
mysql> Select char(65,67.3,69.3);
+--------------------+
| char(65,67.3,69.3) |
+--------------------+
| ACE
|
+--------------------+
1 row in set (0.00 sec)
9
mysql> INSERT INTO pet VALUES ('Puffball','Diane','hamster','f','1999-0330',NULL);
Query OK, 1 row affected (0.07 sec)
10
mysql> Select * from handbags;
+-----------+--------------+-------------+-------------+
| productid | pname
| producttype | productcost |
+-----------+--------------+-------------+-------------+
| 20000
| hidesign
| handbags |
13050 |
| 20001
| lavie
| handbag
|
15000 |
| 20002
| lara caren | clutches |
1200 |
| 20003
| baggit
| wallet
|
13460 |
| 24678
| phive rivers | clutches |
1670 |
| 24678
| 10th planets | wallet
|
15690 |
| 24679
| 3 mad chicks | handbags |
17890 |

+-----------+--------------+-------------+-------------+
7 rows in set (0.00 sec)
11
mysql> Select productid from handbags;
+-----------+
| productid |
+-----------+
| 20000
|
| 20001
|
| 20002
|
| 20003
|
| 24678
|
| 24678
|
| 24679
|
+-----------+
7 rows in set (0.00 sec)
12
mysql> select distinct producttype from handbags;
+-------------+
| producttype |
+-------------+
| handbags |
| handbag
|
| clutches |
| wallet
|
+-------------+
4 rows in set (0.05 sec)
13
mysql> Select all producttype from handbags;
+-------------+
| producttype |
+-------------+
| handbags |
| handbag
|
| clutches |
| wallet
|
| clutches |
| wallet
|
| handbags |
+-------------+
7 rows in set (0.00 sec)
14

mysql> select 1+6;


+-----+
| 1+6 |
+-----+
| 7|
+-----+
1 row in set (0.04 sec)
15
mysql> Select curdate();
+------------+
| curdate() |
+------------+
| 2014-11-12 |
+------------+
1 row in set (0.03 sec)
16
mysql> Select pname,productcost/100 from handbags;
+--------------+-----------------+
| pname
| productcost/100 |
+--------------+-----------------+
| hidesign
|
130.5000 |
| lavie
|
150.0000 |
| lara caren |
12.0000 |
| baggit
|
134.6000 |
| phive rivers |
16.7000 |
| 10th planets |
156.9000 |
| 3 mad chicks |
178.9000 |
+--------------+-----------------+
7 rows in set (0.05 sec)

17
mysql> Select pname,productcost from handbags where productcost<5000;
+--------------+-------------+
| pname
| productcost |
+--------------+-------------+
| lara caren |
1200 |
| phive rivers |
1670 |
+--------------+-------------+
2 rows in set (0.22 sec)
18
mysql> Select pname,producttype from handbags
where(producttype='handbags'or producttype='clutches');

+--------------+-------------+
| pname
| producttype |
+--------------+-------------+
| hidesign
| handbags |
| lara caren | clutches |
| phive rivers | clutches |
| 3 mad chicks | handbags |
+--------------+-------------+
4 rows in set (0.04 sec)

19

mysql> Select *from handbags order by productcost;


+-----------+--------------+-------------+-------------+
| productid | pname
| producttype | productcost |
+-----------+--------------+-------------+-------------+
| 20002
| lara caren | clutches |
1200 |
| 24678
| phive rivers | clutches |
1670 |
| 20000
| hidesign
| handbags |
13050 |
| 20003
| baggit
| wallet
|
13460 |
| 20001
| lavie
| handbag
|
15000 |
| 24678
| 10th planets | wallet
|
15690 |
| 24679
| 3 mad chicks | handbags |
17890 |
+-----------+--------------+-------------+-------------+
7 rows in set (0.32 sec)
20
mysql> Select concat (concat (pname,"has code"),productid) from handbags
where productcost<1600;
+----------------------------------------------+
| concat (concat (pname,"has code"),productid) |
+----------------------------------------------+
| lara carenhas code20002
|
+----------------------------------------------+
1 row in set (0.72 sec)
21
mysql> Select upper(pname)"productname" from handbags;

+--------------+
| productname |
+--------------+
| HIDESIGN
|
| LAVIE
|
| LARA CAREN |
| BAGGIT
|
| PHIVE RIVERS |
| 10TH PLANETS |
| 3 MAD CHICKS |
+--------------+
7 rows in set (0.00 sec)

22
mysql> Select substr('abcdefg',3,4)"subs";
+------+
| subs |
+------+
| cdef |
+------+
1 row in set (0.00 sec)
23
mysql> Select trim(leading'x' from 'xxxxbar one xxxx');
+------------------------------------------+
| trim(leading'x' from 'xxxxbar one xxxx') |
+------------------------------------------+
| bar one xxxx
|
+------------------------------------------+
1 row in set (0.05 sec)
24
mysql> Select trim(both'x' from 'xxxxbar one xxxx');
+---------------------------------------+
| trim(both'x' from 'xxxxbar one xxxx') |
+---------------------------------------+
| bar one
|
+---------------------------------------+
1 row in set (0.00 sec)
25

mysql> Select trim(trailing'x' from 'xxxxbar one xxxx');


+-------------------------------------------+
| trim(trailing'x' from 'xxxxbar one xxxx') |
+-------------------------------------------+
| xxxxbar one
|
+-------------------------------------------+
1 row in set (0.00 sec)

26
mysql> Select producttype,instr(pname,'ie')as "ie in product type" from
handbags;
+-------------+--------------------+
| producttype | ie in product type |
+-------------+--------------------+
| handbags |
0|
| handbag
|
4|
| clutches |
0|
| wallet
|
0|
| clutches |
0|
| wallet
|
0|
| handbags |
0|
+-------------+--------------------+
7 rows in set (0.02 sec)
27
mysql> Select length('candidate')"length in character";
+---------------------+
| length in character |
+---------------------+
|
9|
+---------------------+
1 row in set (0.00 sec)
28
mysql> Select left('uss/23/67/09',3);
+------------------------+
| left('uss/23/67/09',3) |

+------------------------+
| uss
|
+------------------------+
1 row in set (0.00 sec)
29
mysql> Select right('uss/23/67/09',3);
+-------------------------+
| right('uss/23/67/09',3) |
+-------------------------+
| /09
|
+-------------------------+
1 row in set (0.00 sec)

30
mysql> Select mid('Quadratically',5,6);
+--------------------------+
| mid('Quadratically',5,6) |
+--------------------------+
| ratica
|
+--------------------------+
1 row in set (0.00 sec)
31
mysql> Select mod(11,4)"modulus";
+---------+
| modulus |
+---------+
|
3|
+---------+
1 row in set (0.00 sec)
32
mysql> Select power(3,2)"raised";
+--------+
| raised |
+--------+
|
9|
+--------+
1 row in set (0.04 sec)
33

mysql> Select round(15.193,1)"round";


+-------+
| round |
+-------+
| 15.2 |
+-------+
1 row in set (0.00 sec)
34
mysql> Select round(15.193,-1)"round";
+-------+
| round |
+-------+
| 20 |
+-------+
1 row in set (0.00 sec)
35
mysql> Select sign(-15)"sign";
+------+
| sign |
+------+
| -1 |
+------+
1 row in set (0.00 sec)
36
mysql> Select sqrt(26) "square root";
+--------------------+
| square root
|
+--------------------+
| 5.0990195135927845 |
+--------------------+
1 row in set (0.00 sec)
37
mysql> Select truncate(15.79,1)"truncate";
+----------+
| truncate |
+----------+
|
15.7 |
+----------+
1 row in set (0.00 sec)
38

mysql> Select date('2008-12-31 01:02:03');


+-----------------------------+
| date('2008-12-31 01:02:03') |
+-----------------------------+
| 2008-12-31
|
+-----------------------------+
1 row in set (0.05 sec)
39
mysql> Select month('2008-12-31');
+---------------------+
| month('2008-12-31') |
+---------------------+
|
12 |
+---------------------+
1 row in set (0.03 sec)
40
mysql> Select dayname('2008-12-31');
+-----------------------+
| dayname('2008-12-31') |
+-----------------------+
| Wednesday
|
+-----------------------+
1 row in set (0.00 sec)
41
mysql> Select dayofmonth('2008-12-31');
+--------------------------+
| dayofmonth('2008-12-31') |
+--------------------------+
|
31 |
+--------------------------+
1 row in set (0.00 sec)
42
mysql> Select now();
+---------------------+
| now()
|
+---------------------+
| 2014-11-12 15:30:15 |
+---------------------+
1 row in set (0.00 sec)
43

mysql> Select now(),sleep(2),now();


+---------------------+----------+---------------------+
| now()
| sleep(2) | now()
|
+---------------------+----------+---------------------+
| 2014-11-12 15:31:01 |
0 | 2014-11-12 15:31:01 |
+---------------------+----------+---------------------+
1 row in set (2.05 sec)

44
mysql> Select @@autocommit;
+--------------+
| @@autocommit |
+--------------+
|
1|
+--------------+
1 row in set (0.00 sec)
45
mysql> Select avg(productcost)"average" from handbags;
+------------+
| average |
+------------+
| 11137.1429 |
+------------+
1 row in set (0.27 sec)
46
mysql> Select count(*)from handbags;
+----------+
| count(*) |
+----------+
|
7|
+----------+
1 row in set (0.00 sec)
47
mysql> select max(productid)"maximum id" from handbags;
+------------+
| maximum id |
+------------+
| 24679
|
+------------+
1 row in set (0.00 sec)
48

mysql> Select sum(productcost)"productcost" from handbags;


+-------------+
| productcost |
+-------------+
|
77960 |
+-------------+
1 row in set (0.00 sec)

49
mysql> Select count(productid)from handbags group by productcost;
+------------------+
| count(productid) |
+------------------+
|
1|
|
1|
|
1|
|
1|
|
1|
|
1|
|
1|
+------------------+
7 rows in set (0.00 sec)
50
mysql> Select min(productcost)"minimum cost" from handbags;
+--------------+
| minimum cost |
+--------------+
|
1200 |
+--------------+
1 row in set (0.00 sec)

You might also like