0% found this document useful (0 votes)
46 views3 pages

Pratical Cs Mysql

The document shows SQL commands used to create tables, insert data, update data, and run queries on the PRODUCT and CLIENT tables in a MySQL database. The PRODUCT table contains product records with fields for ID, name, manufacturer and price. The CLIENT table links clients to products with fields for client ID, name, city and product ID. Queries are run to select, update, order and join data between the two tables.

Uploaded by

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

Pratical Cs Mysql

The document shows SQL commands used to create tables, insert data, update data, and run queries on the PRODUCT and CLIENT tables in a MySQL database. The PRODUCT table contains product records with fields for ID, name, manufacturer and price. The CLIENT table links clients to products with fields for client ID, name, city and product ID. Queries are run to select, update, order and join data between the two tables.

Uploaded by

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

mysql> show databases;

+--------------------+
| Database |
+--------------------+
| advik |
| employee |
| information_schema |
| mysql |
| performance_schema |
| school |
| sys |
+--------------------+
7 rows in set (0.00 sec)

Database changed
mysql> create table PRODUCT(PID varchar(100),Productname varchar(100),Manufacturer
varchar(100),Price int);
Query OK, 0 rows affected (0.03 sec)

mysql> insert into PRODUCT(PID,Productname,Manufacturer,Price)values('TP01','Talcum


Powder','LAK',40);
Query OK, 1 row affected (0.01 sec)

mysql> insert into PRODUCT(PID,Productname,Manufacturer,Price)values('FWO5','Face


Wash','ABC',45);
Query OK, 1 row affected (0.01 sec)

mysql> insert into PRODUCT(PID,Productname,Manufacturer,Price)values('BS01','Bath


Soap','ABC',55);
Query OK, 1 row affected (0.01 sec)

mysql> insert into


PRODUCT(PID,Productname,Manufacturer,Price)values('SH06','Shampoo','XYZ',120);
Query OK, 1 row affected (0.01 sec)

mysql> insert into PRODUCT(PID,Productname,Manufacturer,Price)values('FW12','Face


Wash','XYZ',95);
Query OK, 1 row affected (0.01 sec)

mysql> select * from PRODUCT;


+------+---------------+--------------+-------+
| PID | Productname | Manufacturer | Price |
+------+---------------+--------------+-------+
| TP01 | Talcum Powder | LAK | 40 |
| FWO5 | Face Wash | ABC | 45 |
| BS01 | Bath Soap | ABC | 55 |
| SH06 | Shampoo | XYZ | 120 |
| FW12 | Face Wash | XYZ | 95 |
+------+---------------+--------------+-------+
5 rows in set (0.00 sec)

mysql> create table CLIENT(CID int,ClientName varchar(100),City varchar(100),PID


varchar(100));
Query OK, 0 rows affected (0.04 sec)

mysql> insert into CLIENT(CID,ClientName,City,PID)values(01,'Cosemetic


shop','Delhi','FW05');
Query OK, 1 row affected (0.01 sec)
mysql> insert into CLIENT(CID,ClientName,City,PID)values(06,'Total
Health','Mumbai','BS01');
Query OK, 1 row affected (0.01 sec)

mysql> insert into CLIENT(CID,ClientName,City,PID)values(12,'Live


Life','Delhi','SH06');
Query OK, 1 row affected (0.01 sec)

mysql> insert into CLIENT(CID,ClientName,City,PID)values(15,'Preety


woman','Delhi','FW12');
Query OK, 1 row affected (0.00 sec)

mysql> insert into


CLIENT(CID,ClientName,City,PID)values(16,'Dreams','Bangalore','TP01');
Query OK, 1 row affected (0.01 sec)

mysql> select * from CLIENT;


+------+----------------+-----------+------+
| CID | ClientName | City | PID |
+------+----------------+-----------+------+
| 1 | Cosemetic shop | Delhi | FW05 |
| 6 | Total Health | Mumbai | BS01 |
| 12 | Live Life | Delhi | SH06 |
| 15 | Preety woman | Delhi | FW12 |
| 16 | Dreams | Bangalore | TP01 |
+------+----------------+-----------+------+
5 rows in set (0.00 sec)

mysql> select * from CLIENT where city=('Delhi');


+------+----------------+-------+------+
| CID | ClientName | City | PID |
+------+----------------+-------+------+
| 1 | Cosemetic shop | Delhi | FW05 |
| 12 | Live Life | Delhi | SH06 |
| 15 | Preety woman | Delhi | FW12 |
+------+----------------+-------+------+
3 rows in set (0.00 sec)

mysql> select * from PRODUCT where price>50 and price<100;


+------+-------------+--------------+-------+
| PID | Productname | Manufacturer | Price |
+------+-------------+--------------+-------+
| BS01 | Bath Soap | ABC | 55 |
| FW12 | Face Wash | XYZ | 95 |
+------+-------------+--------------+-------+
2 rows in set (0.00 sec)

mysql> update PRODUCT set Price = Price + 10;


mysql> select * from PRODUCT;
+------+---------------+--------------+-------+
| PID | Productname | Manufacturer | Price |
+------+---------------+--------------+-------+
| TP01 | Talcum Powder | LAK | 50 |
| FWO5 | Face Wash | ABC | 55 |
| BS01 | Bath Soap | ABC | 65 |
| SH06 | Shampoo | XYZ | 129 |
| FW12 | Face Wash | XYZ | 105 |
+------+---------------+--------------+-------+
5 rows in set (0.00 sec)

mysql> select ClientName,City,ProductName,Price from CLIENT,PRODUCT where


CLIENT.PID = PRODUCT.PID;
+--------------+-----------+---------------+-------+
| ClientName | City | ProductName | Price |
+--------------+-----------+---------------+-------+
| Dreams | Bangalore | Talcum Powder | 50 |
| Total Health | Mumbai | Bath Soap | 65 |
| Live Life | Delhi | Shampoo | 129 |
| Preety woman | Delhi | Face Wash | 105 |
+--------------+-----------+---------------+-------+
4 rows in set (0.00 sec)

mysql> select * from PRODUCT order by Price asc;


+------+---------------+--------------+-------+
| PID | Productname | Manufacturer | Price |
+------+---------------+--------------+-------+
| TP01 | Talcum Powder | LAK | 50 |
| FWO5 | Face Wash | ABC | 55 |
| BS01 | Bath Soap | ABC | 65 |
| FW12 | Face Wash | XYZ | 105 |
| SH06 | Shampoo | XYZ | 129 |
+------+---------------+--------------+-------+
5 rows in set (0.00 sec)

mysql> select * from PRODUCT order by Price desc;


+------+---------------+--------------+-------+
| PID | Productname | Manufacturer | Price |
+------+---------------+--------------+-------+
| SH06 | Shampoo | XYZ | 129 |
| FW12 | Face Wash | XYZ | 105 |
| BS01 | Bath Soap | ABC | 65 |
| FWO5 | Face Wash | ABC | 55 |
| TP01 | Talcum Powder | LAK | 50 |
+------+---------------+--------------+-------+
5 rows in set (0.00 sec)

You might also like