Sunteți pe pagina 1din 8

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.


Your MySQL connection id is 613
Server version: 5.7.21 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its


affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database lab4;


Query OK, 1 row affected (0.20 sec)

mysql> create table customers(ID int primary key, NAME varchar(30), AGE int,
ADDRESS varchar(30), SALARY float);
ERROR 1046 (3D000): No database selected
mysql> use lab4
Database changed
mysql> create table customers(ID int primary key, NAME varchar(30), AGE int,
ADDRESS varchar(30), SALARY float);
Query OK, 0 rows affected (0.71 sec)

mysql> insert into customers values (1, "Ramesh", 32, "Ahmedabad", 2000), (2,
"Khilan",25,"Delhi",1500),(3,"Kaushik",23,"Kota",2000),
(4,"Chaitali",25,"Mumbai",6500);
Query OK, 4 rows affected (0.13 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> insert into customers values (5, "Hardik", 27, "Bhopal", 8500), (6,
"Komal",22,"MP",4500),(7,"Muffy",24,"Indore",10000);
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select * from customers;


+----+----------+------+-----------+--------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+------+-----------+--------+
| 1 | Ramesh | 32 | Ahmedabad | 2000 |
| 2 | Khilan | 25 | Delhi | 1500 |
| 3 | Kaushik | 23 | Kota | 2000 |
| 4 | Chaitali | 25 | Mumbai | 6500 |
| 5 | Hardik | 27 | Bhopal | 8500 |
| 6 | Komal | 22 | MP | 4500 |
| 7 | Muffy | 24 | Indore | 10000 |
+----+----------+------+-----------+--------+
7 rows in set (0.02 sec)

mysql> create view customer_view as select name, age from customers;


Query OK, 0 rows affected (0.26 sec)

mysql> select * from customer_view;


+----------+------+
| name | age |
+----------+------+
| Ramesh | 32 |
| Khilan | 25 |
| Kaushik | 23 |
| Chaitali | 25 |
| Hardik | 27 |
| Komal | 22 |
| Muffy | 24 |
+----------+------+
7 rows in set (0.08 sec)

mysql> select name from customer_view where age=25;


+----------+
| name |
+----------+
| Khilan |
| Chaitali |
+----------+
2 rows in set (0.00 sec)

mysql> Drop view customer_view;


Query OK, 0 rows affected (0.04 sec)

mysql> show tables;


+----------------+
| Tables_in_lab4 |
+----------------+
| customers |
+----------------+
1 row in set (0.08 sec)

mysql> select count(*) from customer where age=25;


ERROR 1146 (42S02): Table 'lab4.customer' doesn't exist
mysql> select count(*) from customers where age=25;
+----------+
| count(*) |
+----------+
| 2 |
+----------+
1 row in set (0.01 sec)

mysql> select count(*) from customers;


+----------+
| count(*) |
+----------+
| 7 |
+----------+
1 row in set (0.00 sec)

mysql> select min(age) from customers;


+----------+
| min(age) |
+----------+
| 22 |
+----------+
1 row in set (0.06 sec)

mysql> select max(age) from customers;


+----------+
| max(age) |
+----------+
| 32 |
+----------+
1 row in set (0.00 sec)

mysql> select avg(salary) from customers;


+-------------+
| avg(salary) |
+-------------+
| 5000 |
+-------------+
1 row in set (0.00 sec)

mysql> select sum(salary) from customers;


+-------------+
| sum(salary) |
+-------------+
| 35000 |
+-------------+
1 row in set (0.00 sec)

mysql> select*from customers;


+----+----------+------+-----------+--------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+------+-----------+--------+
| 1 | Ramesh | 32 | Ahmedabad | 2000 |
| 2 | Khilan | 25 | Delhi | 1500 |
| 3 | Kaushik | 23 | Kota | 2000 |
| 4 | Chaitali | 25 | Mumbai | 6500 |
| 5 | Hardik | 27 | Bhopal | 8500 |
| 6 | Komal | 22 | MP | 4500 |
| 7 | Muffy | 24 | Indore | 10000 |
+----+----------+------+-----------+--------+
7 rows in set (0.00 sec)

mysql> update customers set NAME="Ramesh" where salary=1500;


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

mysql> update customers set NAME="Kaushik" where ADDRESS="kota";


Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0

mysql> select*from customers;


+----+----------+------+-----------+--------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+------+-----------+--------+
| 1 | Ramesh | 32 | Ahmedabad | 2000 |
| 2 | Ramesh | 25 | Delhi | 1500 |
| 3 | Kaushik | 23 | Kota | 2000 |
| 4 | Chaitali | 25 | Mumbai | 6500 |
| 5 | Hardik | 27 | Bhopal | 8500 |
| 6 | Komal | 22 | MP | 4500 |
| 7 | Muffy | 24 | Indore | 10000 |
+----+----------+------+-----------+--------+
7 rows in set (0.00 sec)

mysql> update customers set NAME="Kaushik" where ADDRESS="mumbai";


Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select*from customers;
+----+---------+------+-----------+--------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+---------+------+-----------+--------+
| 1 | Ramesh | 32 | Ahmedabad | 2000 |
| 2 | Ramesh | 25 | Delhi | 1500 |
| 3 | Kaushik | 23 | Kota | 2000 |
| 4 | Kaushik | 25 | Mumbai | 6500 |
| 5 | Hardik | 27 | Bhopal | 8500 |
| 6 | Komal | 22 | MP | 4500 |
| 7 | Muffy | 24 | Indore | 10000 |
+----+---------+------+-----------+--------+
7 rows in set (0.00 sec)

mysql> Select name, sum(salary) from customers group by name;


+---------+-------------+
| name | sum(salary) |
+---------+-------------+
| Hardik | 8500 |
| Kaushik | 8500 |
| Komal | 4500 |
| Muffy | 10000 |
| Ramesh | 3500 |
+---------+-------------+
5 rows in set (0.12 sec)

mysql> select*from customers where address in ("kota","mumbai","indore");


+----+---------+------+---------+--------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+---------+------+---------+--------+
| 3 | Kaushik | 23 | Kota | 2000 |
| 4 | Kaushik | 25 | Mumbai | 6500 |
| 7 | Muffy | 24 | Indore | 10000 |
+----+---------+------+---------+--------+
3 rows in set (0.07 sec)

mysql> select*from customers order by NAME desc;


+----+---------+------+-----------+--------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+---------+------+-----------+--------+
| 1 | Ramesh | 32 | Ahmedabad | 2000 |
| 2 | Ramesh | 25 | Delhi | 1500 |
| 7 | Muffy | 24 | Indore | 10000 |
| 6 | Komal | 22 | MP | 4500 |
| 3 | Kaushik | 23 | Kota | 2000 |
| 4 | Kaushik | 25 | Mumbai | 6500 |
| 5 | Hardik | 27 | Bhopal | 8500 |
+----+---------+------+-----------+--------+
7 rows in set (0.02 sec)

mysql> select*from customers order by NAME desc, AGE asc;


+----+---------+------+-----------+--------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+---------+------+-----------+--------+
| 2 | Ramesh | 25 | Delhi | 1500 |
| 1 | Ramesh | 32 | Ahmedabad | 2000 |
| 7 | Muffy | 24 | Indore | 10000 |
| 6 | Komal | 22 | MP | 4500 |
| 3 | Kaushik | 23 | Kota | 2000 |
| 4 | Kaushik | 25 | Mumbai | 6500 |
| 5 | Hardik | 27 | Bhopal | 8500 |
+----+---------+------+-----------+--------+
7 rows in set (0.01 sec)

mysql> select * from customers where id in (select id from customers where


salary>4500)
-> ;
+----+---------+------+---------+--------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+---------+------+---------+--------+
| 4 | Kaushik | 25 | Mumbai | 6500 |
| 5 | Hardik | 27 | Bhopal | 8500 |
| 7 | Muffy | 24 | Indore | 10000 |
+----+---------+------+---------+--------+
3 rows in set (0.03 sec)

mysql> update customers set salary=salary*0.25 where age in (select age from
customers where age>27);
ERROR 1093 (HY000): You can't specify target table 'customers' for update in FROM
clause
mysql> update customers set salary = salary*0.25 where age in (select age from
customers where age>27);
ERROR 1093 (HY000): You can't specify target table 'customers' for update in FROM
clause
mysql> update table customers set salary = salary*0.25 where age in (select age
from customers where age>27);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'table
customers set salary = salary*0.25 where age in (select age from customers' at line
1
mysql> update customers set salary ="salary*0.25" where age in (select age from
customers where age>27);
ERROR 1093 (HY000): You can't specify target table 'customers' for update in FROM
clause
mysql> update customers set salary = salary*0.25 where age in (select age from
customers where age>27);
ERROR 1093 (HY000): You can't specify target table 'customers' for update in FROM
clause
mysql> select age from customers where age>25;
+------+
| age |
+------+
| 32 |
| 27 |
+------+
2 rows in set (0.00 sec)

mysql> select age from customers where age>27;


+------+
| age |
+------+
| 32 |
+------+
1 row in set (0.00 sec)

mysql> update customers set salary = salary*0.25 where age in (32);


Query OK, 1 row affected (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update customers set salary = salary*0.25 where age = (select age from
customers where age>27);
ERROR 1093 (HY000): You can't specify target table 'customers' for update in FROM
clause
mysql> update customers set salary = salary*0.25 where age in (select age from
customers where age>27);
ERROR 1093 (HY000): You can't specify target table 'customers' for update in FROM
clause
mysql> create view customer_view as select name, age from customers;
Query OK, 0 rows affected (0.09 sec)

mysql> update customers set salary = salary*0.25 where age in (select age from
customers_view where age>27);
ERROR 1146 (42S02): Table 'lab4.customers_view' doesn't exist
mysql> update customers set salary = salary*0.25 where age in (select age from
customer_view where age>27);
ERROR 1443 (HY000): The definition of table 'customer_view' prevents operation
UPDATE on table 'customers'.
mysql> show tables;
+----------------+
| Tables_in_lab4 |
+----------------+
| customer_view |
| customers |
+----------------+
2 rows in set (0.04 sec)

mysql> select * from customer_view;


+---------+------+
| name | age |
+---------+------+
| Ramesh | 32 |
| Ramesh | 25 |
| Kaushik | 23 |
| Kaushik | 25 |
| Hardik | 27 |
| Komal | 22 |
| Muffy | 24 |
+---------+------+
7 rows in set (0.00 sec)

mysql> update customers set salary = salary*0.25 where age in (select age from
customer_view where age>27);
ERROR 1443 (HY000): The definition of table 'customer_view' prevents operation
UPDATE on table 'customers'.
mysql> create database practise;
Query OK, 1 row affected (0.00 sec)

mysql> use practise;


Database changed
mysql> create table tblCustomer (CustId int primary key, Name varchar(30), Address
varchar(30), ContactNo varchar(25));
Query OK, 0 rows affected (0.11 sec)

mysql> insert into tblCustomer values(1, "Sam", "New Delhi",9555555555),


(2,"Rahul","Gurgaon",9666666666),(3,"Hans","Noida",9444444444),
(4,"Jeetu","Delhi",9333333333),(5,"Ankit","Noida",9222222222));
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near ')' at
line 1
mysql> insert into tblCustomer values(1, "Sam", "New Delhi","9555555555"),
(2,"Rahul","Gurgaon","9666666666"),(3,"Hans","Noida","9444444444"),
(4,"Jeetu","Delhi","9333333333"),(5,"Ankit","Noida","9222222222"));
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near ')' at
line 1
mysql> insert into tblCustomer values(1, "Sam", "New Delhi","9555555555"),
(2,"Rahul","Gurgaon","9666666666"));
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near ')' at
line 1
mysql> insert into tblCustomer values(1, "Sam", "New Delhi","9555555555"),
(2,"Rahul","Gurgaon","9666666666"),(3,"Hans","Noida","9444444444"),
(4,"Jeetu","Delhi","9333333333"),(5,"Ankit","Noida","9222222222");
Query OK, 5 rows affected (0.00 sec)
Records: 5 Duplicates: 0 Warnings: 0

mysql>
mysql>
mysql>
mysql>
mysql>
mysql>
mysql>
mysql>
mysql>
mysql>
mysql>
mysql>
mysql>
mysql>
mysql>
mysql>
mysql>
mysql>
mysql>
mysql>
mysql>
mysql>
mysql>
mysql> create table tblProduct(ProductID int primary key, Name Varchar(30),
UnitPrice int, CatID int, EntryDate date and time, ExpiryDate date and time);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'and
time, ExpiryDate date and time)' at line 1
mysql> create table tblProduct(ProductID int primary key, Name Varchar(30),
UnitPrice int, CatID int, EntryDate datetime, ExpiryDate datetime);
Query OK, 0 rows affected (0.10 sec)

mysql> insert into tblProduct values (1,"Dell Computer",25000,1,"2012-10-14


23:05:05","2012-10-16 23:20:40");
Query OK, 1 row affected (0.06 sec)

mysql> insert into tblProduct values (2,"HCL Computer",20000,2,"2012-10-14


12:05:05","2012-10-16 13:20:40");
Query OK, 1 row affected (0.00 sec)
mysql> insert into tblProduct values (3,"Apple Computer",40000,3,"2013-10-14
02:05:05","2013-10-16 10:20:40");
Query OK, 1 row affected (0.00 sec)

mysql> create table tblOrder(OrderId int primary key, ProductID int, Quantity int,
price int,CustomerID int, ContactNo int);
Query OK, 0 rows affected (0.11 sec)

mysql> insert into tblOrder values (1,1,6,150000,1,955555555),(2,2,4,80000,2,null),


(3,2,2,40000,3,9444444444),(4,3,5,200000,4,9333333333);
ERROR 1264 (22003): Out of range value for column 'ContactNo' at row 3
mysql> insert into tblOrder values (1,1,6,150000,1,955555555),
(2,2,4,80000,2,92737263),(3,2,2,40000,3,9444444444),(4,3,5,200000,4,9333333333);
ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'
mysql> insert into tblOrder values (1,1,6,150000,1,955555555),
(2,2,4,80000,2,92737263),(3,2,2,40000,3,9444444444),(4,3,5,200000,4,9333333333);
ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'
mysql> insert into tblOrder values (2,1,6,150000,1,955555555),
(3,2,4,80000,2,92737263),(4,2,2,40000,3,9444444444),(5,3,5,200000,4,9333333333);
ERROR 1062 (23000): Duplicate entry '2' for key 'PRIMARY'
mysql> show tables;
+--------------------+
| Tables_in_practise |
+--------------------+
| tblcustomer |
| tblorder |
| tblproduct |
+--------------------+
3 rows in set (0.00 sec)

mysql> select * from tblOrder;


+---------+-----------+----------+--------+------------+-----------+
| OrderId | ProductID | Quantity | price | CustomerID | ContactNo |
+---------+-----------+----------+--------+------------+-----------+
| 1 | 1 | 6 | 150000 | 1 | 955555555 |
| 2 | 2 | 4 | 80000 | 2 | NULL |
+---------+-----------+----------+--------+------------+-----------+
2 rows in set (0.00 sec)

mysql> insert into tblOrder values (3,2,2,40000,3,9444444444),


(4,3,5,200000,4,9333333333);
ERROR 1264 (22003): Out of range value for column 'ContactNo' at row 1
mysql> insert into tblOrder values (3,2,2,40000,3,9444444),(4,3,5,200000,4,333333);
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0

mysql>

S-ar putea să vă placă și