Mysql Queries
Mysql Queries
Mysql Queries
MYSQL QUERIES
============================================================
Table 1 =
============================================================
Table 2 = Product
mysql> Create table Product (PId int PRIMARY KEY, PName varchar(50)
NOT NULL, Price int NOT NULL, Category varchar(50) NOT NULL, Quantity
int NOT NULL, Admin_id int );
Query OK, 0 rows affected (0.09 sec)
mysql> Insert into Product values(1,"Lenovo
i7","36000","Laptop","20","2382");
Query OK, 1 row affected (0.05 sec)
mysql>
============================================================
Table 3 =
============================================================
Table 4 =
mysql> create table transaction (tid int PRIMARY KEY, pid int NOT
NULL, pname varchar(50) NOT NULL, quantity int NOT NULL, time_date
Date NOT NULL);
Query OK, 0 rows affected (1.74 sec)
============================================================
Table 5 =
mysql> alter table updates add constraint fk_cust2 foreign key (pid)
references Product(Pid);
Query OK, 0 rows affected (3.25 sec)
Records: 0 Duplicates: 0 Warnings: 0
============================================================
QUERIES
============================================================
2.Display all the products between the price range 100000 and 200000.
mysql> select * from Product where Price between 100000 and 200000;
+-----+-------------------------+--------+------------+----------+----
------+
| PId | PName | Price | Category | Quantity |
Admin_id |
+-----+-------------------------+--------+------------+----------+----
------+
| 10 | Samsung Washing Machine | 150000 | Household | 89 |
2376 |
| 13 | Whirlpool Refrigerator | 200000 | Household | 80 |
2376 |
| 101 | Samsung TV | 200000 | Television | 90 |
2376 |
+-----+-------------------------+--------+------------+----------+----
------+
3 rows in set (0.00 sec)
============================================================
============================================================
============================================================
============================================================
============================================================
============================================================
============================================================
============================================================
============================================================
============================================================
mysql> DELIMITER $$
mysql> Create Procedure update_price(pid int,pname varchar(30))
-> begin
-> update Product set Price=10050 where PId=pid and PName=pname;
-> end $$
Query OK, 0 rows affected (0.26 sec)
============================================================
mysql> delimiter //
mysql> create trigger tr11
-> before insert on transaction
-> for each row
-> begin
-> set new.PName=upper(new.PName);
-> end//
Query OK, 0 rows affected (0.88 sec)
============================================================