0% found this document useful (0 votes)
9 views7 pages

dcl and agregatefun

Uploaded by

gowrisri204
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)
9 views7 pages

dcl and agregatefun

Uploaded by

gowrisri204
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/ 7

Enter password: *********

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


Your MySQL connection id is 24
Server version: 8.0.38 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

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> use sridb;


Database changed
mysql> select database();
+------------+
| database() |
+------------+
| sridb |
+------------+
1 row in set (0.00 sec)

mysql> create table customer (


-> cid int primary key,
-> cname varchar(10) not null,
-> cemail varchar(15) unique
-> );
Query OK, 0 rows affected (0.09 sec)

mysql> desc customer;


+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| cid | int | NO | PRI | NULL | |
| cname | varchar(10) | NO | | NULL | |
| cemail | varchar(15) | YES | UNI | NULL | |
+--------+-------------+------+-----+---------+-------+
3 rows in set (0.01 sec)

mysql> insert into customer


-> values(1122,'sri','gowrisri204@g'),
-> (1144,'ram',NULL);
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0

mysql> select *from customer;


+------+-------+---------------+
| cid | cname | cemail |
+------+-------+---------------+
| 1122 | sri | gowrisri204@g |
| 1144 | ram | NULL |
+------+-------+---------------+
2 rows in set (0.00 sec)

mysql> create table accounts (


-> anumber int primary key,
-> atype varchar(10) not null,
-> abalance decimal(15,2) not null,
-> cid int,
-> foreign key(cid) reference customer (cid)
-> );
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
'reference customer (cid)
)' at line 6
mysql> use sridb;
Database changed
mysql> select database();
+------------+
| database() |
+------------+
| sridb |
+------------+
1 row in set (0.00 sec)

mysql> create table accounts(


-> anumber int primary key,
-> atype varchar(10) not null,
-> abalance decimal(15,2) not null,
-> cid int,
-> foreign key(cid) references customer(cid)
-> );
Query OK, 0 rows affected (0.06 sec)

mysql> desc accounts;


+----------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------------+------+-----+---------+-------+
| anumber | int | NO | PRI | NULL | |
| atype | varchar(10) | NO | | NULL | |
| abalance | decimal(15,2) | NO | | NULL | |
| cid | int | YES | MUL | NULL | |
+----------+---------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> insert into accounts(anumber,atype,abalance,cid)


-> values(990041,'savings',125000.71,1122);
Query OK, 1 row affected (0.01 sec)

mysql> select *from accounts;


+---------+---------+-----------+------+
| anumber | atype | abalance | cid |
+---------+---------+-----------+------+
| 990041 | savings | 125000.71 | 1122 |
+---------+---------+-----------+------+
1 row in set (0.00 sec)

mysql> insert into accounts


-> values(990042,'current',125900.32,1144);
Query OK, 1 row affected (0.01 sec)

mysql> select *from accounts;


+---------+---------+-----------+------+
| anumber | atype | abalance | cid |
+---------+---------+-----------+------+
| 990041 | savings | 125000.71 | 1122 |
| 990042 | current | 125900.32 | 1144 |
+---------+---------+-----------+------+
2 rows in set (0.00 sec)

mysql> insert into accounts


-> values(990004,'saving',10250.66,null);(990045,'current',11255.09,1122);
Query OK, 1 row affected (0.01 sec)

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
'990045,'current',11255.09,1122)' at line 1
mysql> select *from accounts;
+---------+---------+-----------+------+
| anumber | atype | abalance | cid |
+---------+---------+-----------+------+
| 990004 | saving | 10250.66 | NULL |
| 990041 | savings | 125000.71 | 1122 |
| 990042 | current | 125900.32 | 1144 |
+---------+---------+-----------+------+
3 rows in set (0.00 sec)

mysql> insert into accounts


-> values(899901,'current',950.94,null);
Query OK, 1 row affected (0.01 sec)

mysql> select *from accounts;


+---------+---------+-----------+------+
| anumber | atype | abalance | cid |
+---------+---------+-----------+------+
| 899901 | current | 950.94 | NULL |
| 990004 | saving | 10250.66 | NULL |
| 990041 | savings | 125000.71 | 1122 |
| 990042 | current | 125900.32 | 1144 |
+---------+---------+-----------+------+
4 rows in set (0.00 sec)

mysql> insert into accounts


-> values(989902,'saving',13500.85,1122);
Query OK, 1 row affected (0.01 sec)

mysql> select *from accounts;


+---------+---------+-----------+------+
| anumber | atype | abalance | cid |
+---------+---------+-----------+------+
| 899901 | current | 950.94 | NULL |
| 989902 | saving | 13500.85 | 1122 |
| 990004 | saving | 10250.66 | NULL |
| 990041 | savings | 125000.71 | 1122 |
| 990042 | current | 125900.32 | 1144 |
+---------+---------+-----------+------+
5 rows in set (0.00 sec)

mysql> delete from customer where cname='sri';


ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint
fails (`sridb`.`accounts`, CONSTRAINT `accounts_ibfk_1` FOREIGN KEY (`cid`)
REFERENCES `customer` (`cid`))
mysql> use sridb;
Database changed
mysql> select database();
+------------+
| database() |
+------------+
| sridb |
+------------+
1 row in set (0.00 sec)

mysql> create user gowri identified by 'SRI';


Query OK, 0 rows affected (0.03 sec)

mysql> grant all on customer to gowri;


Query OK, 0 rows affected (0.01 sec)

mysql> revoke all on customer from gowri;


Query OK, 0 rows affected (0.01 sec)

mysql> select *from accounts;


+---------+---------+-----------+------+
| anumber | atype | abalance | cid |
+---------+---------+-----------+------+
| 899901 | current | 950.94 | NULL |
| 989902 | saving | 13500.85 | 1122 |
| 990004 | saving | 10250.66 | NULL |
| 990041 | savings | 125000.71 | 1122 |
| 990042 | current | 125900.32 | 1144 |
+---------+---------+-----------+------+
5 rows in set (0.00 sec)

mysql> select count (*) from accounts;


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 '*) from
accounts' at line 1
mysql> select count(*) from accounts;
+----------+
| count(*) |
+----------+
| 5 |
+----------+
1 row in set (0.00 sec)

mysql> select count (*) from accounts where abalance>=15000;


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 '*) from
accounts where abalance>=15000' at line 1
mysql> select count(*) from accounts where abalance<=15000;
+----------+
| count(*) |
+----------+
| 3 |
+----------+
1 row in set (0.00 sec)

mysql> select sum(*) from accounts;


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 '*) from
accounts' at line 1
mysql> select sum(*) from accounts;
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 '*) from
accounts' at line 1
mysql> select sum(abalance) from accounts;
+---------------+
| sum(abalance) |
+---------------+
| 275603.48 |
+---------------+
1 row in set (0.00 sec)

mysql> select sum(abalance) from accounts where abalance>=200000;


+---------------+
| sum(abalance) |
+---------------+
| NULL |
+---------------+
1 row in set (0.00 sec)

mysql> select average(abalance) from accounts;


ERROR 1305 (42000): FUNCTION sridb.average does not exist
mysql> select avg(abalance) from accounts;
+---------------+
| avg(abalance) |
+---------------+
| 55120.696000 |
+---------------+
1 row in set (0.00 sec)

mysql> C:\Program Files\MySQL\MySQL Server 8.0\bin


ERROR:
Unknown command '\P'.
ERROR:
Unknown command '\M'.
ERROR:
Unknown command '\M'.
ERROR:
Unknown command '\b'.
->
-> );
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 'C:\
Program Files\MySQL\MySQL Server 8.0\bin

)' at line 1
mysql> select format (avg(abalance),2) as average_balance from accounts;
+-----------------+
| average_balance |
+-----------------+
| 55,120.70 |
+-----------------+
1 row in set (0.00 sec)

mysql> select min(abalance)from accounts;


+---------------+
| min(abalance) |
+---------------+
| 950.94 |
+---------------+
1 row in set (0.00 sec)

mysql> select max(abalance) from accounts;


+---------------+
| max(abalance) |
+---------------+
| 125900.32 |
+---------------+
1 row in set (0.00 sec)

mysql> select *from accounts order by abalance;


+---------+---------+-----------+------+
| anumber | atype | abalance | cid |
+---------+---------+-----------+------+
| 899901 | current | 950.94 | NULL |
| 990004 | saving | 10250.66 | NULL |
| 989902 | saving | 13500.85 | 1122 |
| 990041 | savings | 125000.71 | 1122 |
| 990042 | current | 125900.32 | 1144 |
+---------+---------+-----------+------+
5 rows in set (0.00 sec)

mysql> select *from accounts order by abalance desc;


+---------+---------+-----------+------+
| anumber | atype | abalance | cid |
+---------+---------+-----------+------+
| 990042 | current | 125900.32 | 1144 |
| 990041 | savings | 125000.71 | 1122 |
| 989902 | saving | 13500.85 | 1122 |
| 990004 | saving | 10250.66 | NULL |
| 899901 | current | 950.94 | NULL |
+---------+---------+-----------+------+
5 rows in set (0.00 sec)

mysql> select atype, count(*) as Tt1_acnts


-> from accounts group by atype;
+---------+-----------+
| atype | Tt1_acnts |
+---------+-----------+
| current | 2 |
| saving | 2 |
| savings | 1 |
+---------+-----------+
3 rows in set (0.00 sec)

mysql> select atype,count(*) as Tt1_acnts


-> from accounts group by atype having count(*)>1;
+---------+-----------+
| atype | Tt1_acnts |
+---------+-----------+
| current | 2 |
| saving | 2 |
+---------+-----------+
2 rows in set (0.00 sec)

mysql> select *from customer inner join accounts on customer.cid=accounts.cid;


+------+-------+---------------+---------+---------+-----------+------+
| cid | cname | cemail | anumber | atype | abalance | cid |
+------+-------+---------------+---------+---------+-----------+------+
| 1122 | sri | gowrisri204@g | 989902 | saving | 13500.85 | 1122 |
| 1122 | sri | gowrisri204@g | 990041 | savings | 125000.71 | 1122 |
| 1144 | ram | NULL | 990042 | current | 125900.32 | 1144 |
+------+-------+---------------+---------+---------+-----------+------+
3 rows in set (0.00 sec)

mysql> select *from customer left join accounts on customer.cid=accounts.cid;


+------+--------+---------------+---------+---------+-----------+------+
| cid | cname | cemail | anumber | atype | abalance | cid |
+------+--------+---------------+---------+---------+-----------+------+
| 1122 | sri | gowrisri204@g | 989902 | saving | 13500.85 | 1122 |
| 1122 | sri | gowrisri204@g | 990041 | savings | 125000.71 | 1122 |
| 1144 | ram | NULL | 990042 | current | 125900.32 | 1144 |
| 1166 | vishwa | NULL | NULL | NULL | NULL | NULL |
+------+--------+---------------+---------+---------+-----------+------+
4 rows in set (0.00 sec)

mysql>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy