0% found this document useful (0 votes)
4 views

SQL_PART1

The document provides an overview of Structured Query Language (SQL) and its role in managing databases, including definitions of key concepts such as databases, database management systems, and database administrators. It outlines the structure of relational databases, including tables, keys, and integrity constraints, as well as SQL commands for data definition, manipulation, and control. Additionally, it discusses the importance of avoiding data redundancy and inconsistency, and provides examples of SQL commands for creating and modifying database structures.

Uploaded by

Aradhya Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

SQL_PART1

The document provides an overview of Structured Query Language (SQL) and its role in managing databases, including definitions of key concepts such as databases, database management systems, and database administrators. It outlines the structure of relational databases, including tables, keys, and integrity constraints, as well as SQL commands for data definition, manipulation, and control. Additionally, it discusses the importance of avoiding data redundancy and inconsistency, and provides examples of SQL commands for creating and modifying database structures.

Uploaded by

Aradhya Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 104

STRUCTURED QUERY LANGUAGE

DATABASE-It is a computer based recording system to store collection of


interrelated data to serve the needs of multiple applications which allows
users to access, modify ,search, update and perform some other useful
operations on the data.

DATABASE MANAGEMENT SYSTEM:-Software that is responsible for


organizing and maintaining the database is known as database
management system.

DBA-Database Administrator-The whole responsibility of managing,


organizing and granting privileges to different people in different
department lies on the shoulders of Data base administrator.
STRUCTURED QUERY LANGUAGE
STANDARDS TO BE FOLLOWED FOR DATABASE MANAGEMENT SYSTEM AND ITS
ADVANTAGES
1. DATA REDUNDANCY IS TO BE AVOIDED
Duplication of the data is known as data redundancy.(multiple copies of
same object/PERSON/THING ETC.,)
2. DATA INCONSISTENCY IS TO BE ELEMINATED
DATA REDUNDANCY leads to DATA INCONSISTENCY.(Mismatched multiple
copies of same data)
3. SHAREABLE :- Data can accessed by multiple users
4. SECURE DATA:-Data is secured and is accessible by genuine/authorized
person who can login using credentials .
STRUCTURED QUERY LANGUAGE
In databases, data is stored in the form of table/s which contains rows and
columns.
The table is referred as a relation
Relational Database Management System since the rows in a table
represents a relationship among set of values.
COMPONENTS OF A TABLE
DATA ITEM- one type of information referred as field
RECORD-Rows containing named collected of data items which is a
complete unit of information.
TABLE:- it is referred as relation which is a collection of records.
FIELDS:-The column containing one type of information is known as field
STRUCTURED QUERY LANGUAGE

Tuple:-Row of the table(relation) is referred as


tuple
Attribute:-The field of the table(relation) is
referred as attribute.
Degree:-The degree of the relation is the total
number of attributes of the relation.
Cardinality:-The cardinality of the relation is the
total number of tuples of the relation.
STRUCTURED QUERY LANGUAGE

VIEWS:-The view does not contain data of its own. It is a kind of relation whose data is
derived from the one or more relations.

KEYS:-
PRIMARY KEY:-Set of one or more than one attribute carries unique values is known as
primary key

CANDIDATE KEY:-In a relation, more than one attribute can prove their candidature to
become the primary key is known as

ALTERNATE KEY:-Candidate key which is not a primary key is called alternate key

FOREIGN KEY:-It manages the relationship between two relations. It is a non key
attribute that derives its values from primary key of another table.
STRUCTURED QUERY LANGUAGE

REFERENTIAL INTEGRITY:-it is a set of rules followed by DBMS to ensure


that the relationship between records of the related table is maintained in
such a way so that accidental deletion or changing of data is not done.

MYSQL DATABASE:- it is the combination of my sql server instance and


mysql database.

SQL(STRUCTURED QUERY LANGUAGE):-Structured Query Language is used


to access the data from SQL database.
STRUCTURED QUERY LANGUAGE

SQL commands can be divided into

1. Data Definition Language Commands


2. Data Manipulation Language Commands
3. Data Control Language Commands
4. Session Control Commands
STRUCTURED QUERY LANGUAGE

Data Definition Language:-Create table, alter table, drop table , rename


table etc., come under Data Definition Language

Data Manipulation Language:-Select data, delete data , insert data, update


data commands belong to Data Manipulation Language

Data /Transaction Control Language:-commit, rollback , save point etc.


STRUCTURED QUERY LANGUAGE
STORE
ID SNAME AREA

S001 ABC Computeronics CP

S002 All Info tech Media GK II

S003 Tech Shoppee CP

S004 Geeks Tecno Soft Nehru Place

S005 Hitech Tech Store Nehru Place


STRUCTURED QUERY LANGUAGE
HARDWARE
N0 NAME PRICE ID
A01 Mother Board 12000 S001
A02 Hard Disk 5000 S001
A03 Key Board 500 S002
A04 Mouse 300 S001
A05 Mother Board 13000 S002
A06 Key Board 400 S003
A07 LCD 6000 S004
T08 LCD 5500 S005
T09 Mouse 350 S005
T10 Harddisk 4500 S003
STRUCTURED QUERY LANGUAGE
DEPARTMENT

SL.NO DNO DEPARTMENT


1 10 IP
2 20 BST
3 30 ACCOUNTANCY
4 40 ENGLISH
5 60 ECONOMICS
6 70 STATISTICS
STRUCTURED QUERY LANGUAGE
EMPLOYEE
EID ENAME VID DNO UID
1001 VIJAY V100 10 1001-10
1002 RANI V200 20 1002-20
1003 SUKANYA V300 10 1003-30
1004 RICHARD V400 30 1004-40
1005 ALI V500 30 1005-50
1006 SANDEEP V600 40 1006-60
1007 RAMESH V700 20 1007-70
1008 SUDHA V800 20 1008-80
1009 KRISHNA V900 40 1009-90
1010 RANVEER V1000 60 1010-100
STRUCTURED QUERY LANGUAGE

• ANSWER THE FOLLOWING QUESTIONS:-


• 1. What is degree of the table STORE?
• 2. What is cardinality of the relation STORE?
• 3. What is the primary key of the relation
STORE?
• 4. What is the alternate key of the relation
STORE?
STRUCTURED QUERY LANGUAGE

ANSWER THE FOLLOWING QUESTIONS:-


5. What is degree of the table HARDWARE?
6. What is cardinality of the relation HARDWARE?
7. What is the primary key of the relation
HARDWARE?
8. Which is the alternate key of the relation
HARDWARE?
9. Which is the foreign key of the relation
HARDWARE?
STRUCTURED QUERY LANGUAGE
Go to website www.mysql.org and download sql 8.0 or which ever is compatible with your OS
Data type available in SQL are

1. Numeric
2. Date and time
3. String

Numeric data types:-integer, int, tinyint , smallint, mediumint, bigint, float(m,d) (m is the length
and d is the decimal) double(m,d), decimal(m,d)
Date and Time—date-in yyyy-mm-dd format , datetime(yyyy-mm-dd hh:mm:ss format ,
timestamp, time, year(m) m stands for 2 or 4 digit.
String/text type-char(m) length can be between 1-255 characters char (5) can accept 5
characters, char –by default accepts 1 character. BLOB or text to store large amount of data
, varchar© is used to store strings of variable length .
Char is used to store strings of fixed length
STRUCTURED QUERY LANGUAGE

Comment statements can written in the following ways

/* This is to implement
Multiline comment statement */

-- implement single line comment statement

# another way of implementing single line comment statement

Commands in SQL are not case sensitive.


STRUCTURED QUERY LANGUAGE

From start button , go to mysql 8.0 command line client. Here the
programmer has to enter mysql (all in small letters )as a password.
STRUCTURED QUERY LANGUAGE
For creating the database use the following command
create database organization;-This command is used for for creating the database
Query OK, 1 row affected (0.87 sec)

mysql> show databases;--used for displaying the available databases.


+--------------------+
| Database |
+--------------------+
| data1 |
| db1 |
| diamonds |
| emp |
| information_schema |
| library |
| mysql |
| organization |
| pearls |
| performance_schema |
| sakila |
| sch_mnt |
STRUCTURED QUERY LANGUAGE

mysql> Create database organization;-This command is used to create the


database
mysql>use organization;--This command is used to open the particular
database for use.
“Database changed” message will displayed on the screen.
Databases is the storage container for tables, queries, reports forms etc.,
Show tables command is used to display available tables
mysql> show tables;--if tables are available in the used databases, then
those tables will be displayed. If tables are not available then the user has
to create the table.
STRUCTURED QUERY LANGUAGE

mysql> create table employee


-> (
-> empid int primary key,
-> enm char(20),
-> gender char(1),
-> esal decimal(6,2)
-> );
Query OK, 0 rows affected (2.52 sec)
STRUCTURED QUERY LANGUAGE

Modify is used to change the size of the column. If the data is already in
that particular column, the size of that field can be increased but cannot be
decreased.
mysql> alter table employee
-> modify enm varchar(100);
Query OK, 0 rows affected (2.05 sec)

Change command is used for changing the name of the column and size of
the column can be increased.
mysql> alter table employee
-> change enm ename varchar(100);
Query OK, 8 rows affected (2.88 sec)
STRUCTURED QUERY LANGUAGE

mysql> alter table employee


-> add dno int;

mysql> alter table emp


-> add foreign key (dno) references department(dno);
mysql> alter table employee-modify size
-> modify enm varchar(50) not null unique;

mysql> alter table employee


-> modify enm varchar(30) default "XYZ";

mysql> ALTER TABLE EMPLOYEE


-> DROP FOREIGN KEY EMPLOYEE_IBFK_1;
STRUCTURED QUERY LANGUAGE

mysql> ALTER TABLE DEPARTMENT


-> DROP DNM;
Query OK, 0 rows affected (1.86 sec)

mysql> alter table employee


-> add check (doj<dor);

mysql> alter table employee


-> change enm ename varchar(50);

mysql> alter table emp1


-> rename emp;
STRUCTURED QUERY LANGUAGE

mysql> ALTER TABLE EMPLOYEE


-> ADD FOREIGN KEY F1(DNO) REFERENCES DEPARTMENT (DNO) ON DELETE
CASCADE ON UPDATE CASCADE;
Query OK, 11 rows affected (3.06 sec)
mysql> insert into
employee(eid,enm,egender,esal,ano,doj,dno,dor)values(1022,"suman","m",34567
8.98,1023,'1999-09-09',100,'2010-09-09');
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint
fails (`organization`.`employee`, CONSTRAINT `employee_ibfk_4` FOREIGN KEY
(`dno`) REFERENCES `department` (`dno`))
mysql> delete from department where dno=30;
ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key
constraint fails (`organization`.`employee`, CONSTRAINT `employee_ibfk_4`
FOREIGN KEY (`dno`) REFERENCES `department` (`dno`))
STRUCTURED QUERY LANGUAGE

mysql> alter table department


-> drop dno cascade;
ERROR 1829 (HY000): Cannot drop column 'dno':
needed in a foreign key constraint
'employee_ibfk_1' of table 'employee'
STRUCTURED QUERY LANGUAGE

• mysql> desc employee;-displays all the columns of the realtion


along with the description.
• +--------+--------------+------+-----+---------+-------+
• | Field | Type | Null | Key | Default | Extra |
• +--------+--------------+------+-----+---------+-------+
• | empid | int | YES | | NULL | |
• | empnm | varchar(50) | YES | | NULL | |
• | gender | char(1) | YES | | NULL | |
• | empsal | decimal(5,2) | YES | | NULL | |
• +--------+--------------+------+-----+---------+-------+
• 4 rows in set (0.05 sec)
STRUCTURED QUERY LANGUAGE

• Drop command is used remove the table


along with records.
• It is a DDL command
• mysql> drop table emp;
STRUCTURED QUERY LANGUAGE

Database Integrity Constraints:-Constrains ensure that the right data is


entered into the table.

The constraints are as follows:


1. Unique constraint
2. Primary key constraint- unique+not null
3. Default constraint
4. Check constraint
5. Foreign key constraint
6. Not null constraint—no column should be empty
STRUCTURED QUERY LANGUAGE

Unique constraint:-

1. This unique constraint ensures that no two rows have the same value
in the column which was assigned with this key constraint.
2. It also ensures that there cannot exist more than one null value in the
column.
3. A column that is unique may or may not be a primary key.
4. Multiple unique constrains can be defined on a table
Create table employee
(
Ecode integer not null, unique
);
STRUCTURED QUERY LANGUAGE

Primary key:-

1. It is similar to unique constraint, The only difference is unique accepts null values
whereas primary key does not.

2. In a table, multiple columns with unique constraints can exist but there can exist only
one column or one combination with primary key.

3. As primary key does not accept null value the column must also be applied with not
null constraint.
Create table employee
(
Ecode integer not null primary key
);
STRUCTURED QUERY LANGUAGE

Default constraint :-

This constraint is specified for a column, using the default clause if user
does not enter a value for a particular column.
Create table employee
(
Ecode integer not null, primary key,
Enm char(10),
gender char(1) default “T”
);
The default value will be entered in case the user does not accept the value
STRUCTURED QUERY LANGUAGE

CHECK CONSTRAINT:-

This constraint checks the values should be as per the criteria mentioned.
create table employee1
(
Ecode integer not null primary key,
Enm char(10),
Grade char(2) default “E2”,
Sal decimal check(Sal>2000)
);
STRUCTURED QUERY LANGUAGE

Foreign key

In Relational database Management system, referential integrity is


followed which ensures that the relationship between records in related
tables are maintained to avoid accidental deletions and updating. This is
ensured through foreign key constraint.
Create table department Create table employee
( (
Dno int not null, primary key, Eid int not null, primary key,
Dname char(20) Dno int references department(dno),
); Enm char(5)
);
STRUCTURED QUERY LANGUAGE

NOT NULL CONSTRAINT

Not null constraint ensures that no column will empty.


The column of the table should contain value for every record of the table.

Create table employee


(
Ecode integer not null, unique
);
STRUCTURED QUERY LANGUAGE

mysql> create table emp1


-> (
-> eid int primary key,
-> enm varchar(50) not null,
-> ano int unique,
-> egender char(1),
-> esal decimal(5,2) check (esal>10000),
-> doj date,
-> dno int,
-> foreign key(dno) references department(dno)
-> );
Query OK, 0 rows affected (0.57 sec)
STRUCTURED QUERY LANGUAGE

DATA MANIPULATION LANGUAGE:-select, delete, update, insert


commands

For inserting records into the table the command should written as follows

mysql> insert into employee (eid,enm,egender,esal,doj)values


(1010,"rani","f",16670.45,'2004-03-14');
Query OK, 1 row affected (0.08 sec)
STRUCTURED QUERY LANGUAGE

Select command is used to select all the records of the relation.


Select command can also be used to select the records of the relation as
per criteria specified by the user.
For restricting the extraction of records from the relation “where”
clause should be used.
The display of the rows of the table can be restricted by giving
conditions.


For displaying all fields of the relation “employee” “*” is used.
STRUCTURED QUERY LANGUAGE

mysql> select * from employee;


+------+-----------+---------+----------+------------+
| eid | enm | egender | esal | doj |
+------+-----------+---------+----------+------------+
| 1001 | sudhir | m | 55000.45 | 1968-08-25 |
| 1002 | sudhiksha | f | 65000.45 | 1999-08-25 |
| 1003 | nitin | m | 75000.45 | 2000-06-25 |
| 1004 | kirit | t | 65500.45 | 2001-06-25 |
| 1005 | ayan | m | 85500.45 | 2002-06-25 |
| 1006 | mansi | f | 86500.45 | 2002-06-14 |
| 1007 | nehal | f | 86600.45 | 2002-07-14 |
| 1008 | ayush | m | 86670.45 | 2002-04-14 |
| 1009 | rajesh | m | 26670.45 | 2001-04-14 |
| 1010 | rani | f | 16670.45 | 2004-03-14 |
+------+-----------+---------+----------+------------+
10 rows in set (0.00 sec)
STRUCTURED QUERY LANGUAGE
the user wants to restrict the fields names in the display then the required fields only to be mentioned in the query.
mysql> select eid, esal ,doj from employee;
+------+----------+------------+
| eid | esal | doj |
+------+----------+------------+
| 1001 | 55000.45 | 1968-08-25 |
| 1002 | 65000.45 | 1999-08-25 |
| 1003 | 75000.45 | 2000-06-25 |
| 1004 | 65500.45 | 2001-06-25 |
| 1005 | 85500.45 | 2002-06-25 |
| 1006 | 86500.45 | 2002-06-14 |
| 1007 | 86600.45 | 2002-07-14 |
| 1008 | 86670.45 | 2002-04-14 |
| 1009 | 26670.45 | 2001-04-14 |
| 1010 | 16670.45 | 2004-03-14 |
+------+----------+------------+
10 rows in set (0.00 sec)
STRUCTURED QUERY LANGUAGE
mysql> select * from employee where eid=1009;

+------+--------+---------+----------+------------+
| eid | enm | egender | esal | doj |
+------+--------+---------+----------+------------+
| 1009 | rajesh | m | 26670.45 | 2001-04-14 |
+------+--------+---------+----------+------------+
1 row in set (0.00 sec)
STRUCTURED QUERY LANGUAGE

mysql> select eid,enm,esal from employee where eid=1009;


In the above command both columns and rows are restricted.
+------+--------+----------+
| eid | enm | esal |
+------+--------+----------+
| 1009 | rajesh | 26670.45 |
+------+--------+----------+
1 row in set (0.00 sec)
STRUCTURED QUERY LANGUAGE

“order by” clause followed by the column name is used to display the
records either in ascending order or in the descending order.

If the records are to be displayed in ascending order order by column


name to be followed by asc; if the the user doer not mention anything by
default it will printed in the ascending order.

If the records to be displayed in descending order than the column name


should be followed by desc;
STRUCTURED QUERY LANGUAGE
mysql> select * from employee order by esal;
+------+-----------+---------+----------+------------+
| eid | enm | egender | esal | doj |
+------+-----------+---------+----------+------------+
| 1010 | rani | f | 16670.45 | 2004-03-14 |
| 1009 | rajesh | m | 26670.45 | 2001-04-14 |
| 1001 | sudhir | m | 55000.45 | 1968-08-25 |
| 1002 | sudhiksha | f | 65000.45 | 1999-08-25 |
| 1004 | kirit | t | 65500.45 | 2001-06-25 |
| 1003 | nitin | m | 75000.45 | 2000-06-25 |
| 1005 | ayan | m | 85500.45 | 2002-06-25 |
| 1006 | mansi | f | 86500.45 | 2002-06-14 |
| 1007 | nehal | f | 86600.45 | 2002-07-14 |
| 1008 | ayush | m | 86670.45 | 2002-04-14 |
+------
STRUCTURED QUERY LANGUAGE
mysql> select * from employee order by eid desc;
+------+-----------+---------+----------+------------+
| eid | enm | egender | esal | doj |
+------+-----------+---------+----------+------------+
| 1010 | rani | f | 16670.45 | 2004-03-14 |
| 1009 | rajesh | m | 26670.45 | 2001-04-14 |
| 1008 | ayush | m | 86670.45 | 2002-04-14 |
| 1007 | nehal | f | 86600.45 | 2002-07-14 |
| 1006 | mansi | f | 86500.45 | 2002-06-14 |
| 1005 | ayan | m | 85500.45 | 2002-06-25 |
| 1004 | kirit | t | 65500.45 | 2001-06-25 |
| 1003 | nitin | m | 75000.45 | 2000-06-25 |
| 1002 | sudhiksha | f | 65000.45 | 1999-08-25 |
| 1001 | sudhir | m | 55000.45 | 1968-08-25 |
+------+-----------+---------+----------+------------+
STRUCTURED QUERY LANGUAGE
mysql> select * from employee order by eid desc;
+------+-----------+---------+----------+------------+
| eid | enm | egender | esal | doj |
+------+-----------+---------+----------+------------+
| 1010 | rani | f | 16670.45 | 2004-03-14 |
| 1009 | rajesh | m | 26670.45 | 2001-04-14 |
| 1008 | ayush | m | 86670.45 | 2002-04-14 |
| 1007 | nehal | f | 86600.45 | 2002-07-14 |
| 1006 | mansi | f | 86500.45 | 2002-06-14 |
| 1005 | ayan | m | 85500.45 | 2002-06-25 |
| 1004 | kirit | t | 65500.45 | 2001-06-25 |
| 1003 | nitin | m | 75000.45 | 2000-06-25 |
| 1002 | sudhiksha | f | 65000.45 | 1999-08-25 |
| 1001 | sudhir | m | 55000.45 | 1968-08-25 |
+------+-----------+---------+----------+------------+
STRUCTURED QUERY LANGUAGE
mysql> select eid,enm,esal, dno from employee where eid>1005 order by
esal, dno desc;
+------+---------+----------+------+
| eid | enm | esal | dno |
+------+---------+----------+------+
| 1011 | mehak | 82000.53 | 70 |
| 1010 | sejal | 85000.53 | 70 |
| 1009 | saksham | 85000.53 | 60 |
| 1008 | XYZ | 85000.53 | 50 |
| 1006 | meha | 85000.53 | 40 |
| 1012 | ramesh | 88000.00 | 50 |
+------+---------+----------+------+
STRUCTURED QUERY LANGUAGE
Relational operators:-<, >, <-, >=, <> are relational operators
Logical operators-not and or are logical operators
Between operator is used for specifying the range
“in” operator is used to find out values in passed vales
“not in” is used to find out not matching records of passed value
mysql> select * from employee where esal>=55000;
+------+-----------+---------+----------+------------+
| eid | enm | egender | esal | doj |
+------+-----------+---------+----------+------------+
| 1001 | sudhir | m | 55000.45 | 1968-08-25 |
| 1002 | sudhiksha | f | 65000.45 | 1999-08-25 |
| 1003 | nitin | m | 75000.45 | 2000-06-25 |
| 1004 | kirit | t | 65500.45 | 2001-06-25 |
| 1005 | ayan | m | 85500.45 | 2002-06-25 |
| 1006 | mansi | f | 86500.45 | 2002-06-14 |
| 1007 | nehal | f | 86600.45 | 2002-07-14 |
| 1008 | ayush | m | 86670.45 | 2002-04-14 |
+------+-----------+---------+----------+------------+
8 rows in set (0.00 sec)
STRUCTURED QUERY LANGUAGE

mysql> select * from employee where esal=65500.45;


+------+-------+---------+----------+------------+
| eid | enm | egender | esal | doj |
+------+-------+---------+----------+------------+
| 1004 | kirit | t | 65500.45 | 2001-06-25 |
+------+-------+---------+----------+------------+
1 row in set (0.00 sec)
STRUCTURED QUERY LANGUAGE
mysql> select * from employee where esal between 55000 and 85000;
The above command is used to display the salary of all those employees whose
salary is between 55000 and 85000 inclusive of both specified in the range.
+------+-----------+---------+----------+------------+
| eid | enm | egender | esal | doj |
+------+-----------+---------+----------+------------+
| 1001 | sudhir | m | 55000.45 | 1968-08-25 |
| 1002 | sudhiksha | f | 65000.45 | 1999-08-25 |
| 1003 | nitin | m | 75000.45 | 2000-06-25 |
| 1004 | kirit | t | 65500.45 | 2001-06-25 |
+------+-----------+---------+----------+------------+
4 rows in set (0.04 sec)
STRUCTURED QUERY LANGUAGE
mysql> SELECT * FROM EMPLOYEE WHERE ESAL NOT BETWEEN 70000 AND 80000;
Between includes both lower and higher range.
+------+---------+---------+----------+-------+------------+------+------------+
| eid | enm | egender | esal | ano | doj | dno | DOR |
+------+---------+---------+----------+-------+------------+------+------------+
| 1005 | nehaal | f | 83000.23 | 10005 | 1998-03-05 | 30 | NULL |
| 1006 | meha | f | 85000.53 | 10006 | 1998-03-04 | 40 | NULL |
| 1008 | XYZ | f | 85000.53 | 10007 | 1997-03-05 | 50 | NULL |
| 1009 | saksham | m | 85000.53 | 10009 | 1996-12-05 | 60 | NULL |
| 1010 | sejal | f | 85000.53 | 10010 | 1994-12-22 | 70 | NULL |
| 1011 | mehak | f | 82000.53 | NULL | 1998-11-22 | 70 | NULL |
| 1012 | ramesh | m | 88000.00 | NULL | 1995-06-02 | 50 | 2020-06-02 |
+------+---------+---------+----------+-------+------------+------+------------+
7 rows in set (0.03 sec)
STRUCTURED QUERY LANGUAGE
select * from employee where eid <>1004;
+------+-----------+---------+----------+------------+
| eid | enm | egender | esal | doj |
+------+-----------+---------+----------+------------+
| 1001 | sudhir | m | 55000.45 | 1968-08-25 |
| 1002 | sudhiksha | f | 65000.45 | 1999-08-25 |
| 1003 | nitin | m | 75000.45 | 2000-06-25 |
| 1005 | ayan | m | 85500.45 | 2002-06-25 |
| 1006 | mansi | f | 86500.45 | 2002-06-14 |
| 1007 | nehal | f | 86600.45 | 2002-07-14 |
| 1008 | ayush | m | 86670.45 | 2002-04-14 |
| 1009 | rajesh | m | 26670.45 | 2001-04-14 |
| 1010 | rani | f | 16670.45 | 2004-03-14 |
+------+-----------+---------+----------+------------+
9 rows in set (0.06 sec)
STRUCTURED QUERY LANGUAGE

select * from employee where esal >=75000 and egender="m";


+------+-------+---------+----------+------------+
| eid | enm | egender | esal | doj |
+------+-------+---------+----------+------------+
| 1003 | nitin | m | 75000.45 | 2000-06-25 |
| 1005 | ayan | m | 85500.45 | 2002-06-25 |
| 1008 | ayush | m | 86670.45 | 2002-04-14 |
+------+-------+---------+----------+------------+
3 rows in set (0.00 sec)
STRUCTURED QUERY LANGUAGE

mysql> select * from employee where esal >=95000 or egender="m";


+------+--------+---------+----------+------------+
| eid | enm | egender | esal | doj |
+------+--------+---------+----------+------------+
| 1001 | sudhir | m | 55000.45 | 1968-08-25 |
| 1003 | nitin | m | 75000.45 | 2000-06-25 |
| 1005 | ayan | m | 85500.45 | 2002-06-25 |
| 1008 | ayush | m | 86670.45 | 2002-04-14 |
| 1009 | rajesh | m | 26670.45 | 2001-04-14 |
+------+--------+---------+----------+------------+
5 rows in set (0.00 sec)
STRUCTURED QUERY LANGUAGE

mysql> select * from employee where esal in(45000,55000.45,85500);


+------+--------+---------+----------+------------+
| eid | enm | egender | esal | doj |
+------+--------+---------+----------+------------+
| 1001 | sudhir | m | 55000.45 | 1968-08-25 |
+------+--------+---------+----------+------------+
1 row in set (0.04 sec)
STRUCTURED QUERY LANGUAGE

mysql> select * from employee where egender not in("m","f");


+------+-------+---------+----------+------------+
| eid | enm | egender | esal | doj |
+------+-------+---------+----------+------------+
| 1004 | kirit | t | 65500.45 | 2001-06-25 |
+------+-------+---------+----------+------------+
1 row in set (0.00 sec)
RELATIONAL DATABASE
mysql> select enm from employee where eid=1005 && dor is null;
+--------+
| enm |
+--------+
| nehaal |
mysql> SELECT ENM FROM EMPLOYEE WHERE EID=1005 ||
ENM="RAMESH";
+--------+
| ENM |
+--------+
| nehaal |
| ramesh |
+--------+
STRUCTURED QUERY LANGUAGE

Count(*) is used to count number of records available in the table.


mysql> select count(*) from employee;
+----------+
| count(*) |
+----------+
| 10 |
+----------+
1 row in set (0.09 sec)
STRUCTURED QUERY LANGUAGE
mysql> select distinct(dno) from employee;
Distinct is used to suppress duplicate elements
+------+
| dno |
+------+
| 10 |
| 20 |
| 60 |
| 40 |
| 30 |
| 50 |
+------+
6 rows in set (0.01 sec)
STRUCTURED QUERY LANGUAGE
mysql> select distinct(dno) from employee;
Distinct is used to suppress duplicate elements
+------+
| dno |
+------+
| 10 |
| 20 |
| 60 |
| 40 |
| 30 |
| 50 |
+------+
6 rows in set (0.01 sec)
STRUCTURED QUERY LANGUAGE
mysql> SELECT ALL (DNO) FROM EMPLOYEE;
+------+
| DNO |
+------+
| 10 |
| 10 |
| 20 |
| 30 |
| 30 |
| 40 |
| 50 |
| 50 |
| 60 |
| 70 |
| 70 |
+------+
11 rows in set (0.04 sec)
STRUCTURED QUERY LANGUAGE

count(distinct(dno))-is used to count suppressing duplicate elements.

mysql> select count(distinct(dno)) from employee;


+----------------------+
| count(distinct(dno)) |
+----------------------+
| 6|
+----------------------+
1 row in set (0.05 sec)
STRUCTURED QUERY LANGUAGE

Max() function is used to extract max of the column specified


mysql> select max(esal) from employee;
+-----------+
| max(esal) |
+-----------+
| 86670.45 |
+-----------+
1 row in set (0.01 sec)
STRUCTURED QUERY LANGUAGE

mysql> select min(esal) from employee;


+-----------+
| min(esal) |
+-----------+
| 16670.45 |
+-----------+
1 row in set (0.00 sec)
STRUCTURED QUERY LANGUAGE

Sum() function is used to find sum of the column specified

mysql> select sum(esal) from employee;


+-----------+
| sum(esal) |
+-----------+
| 649114.50 |
+-----------+
1 row in set (0.00 sec)
STRUCTURED QUERY LANGUAGE

Avg() is used to find out the average of the column specified.

mysql> select avg(esal) from employee;


+--------------+
| avg(esal) |
+--------------+
| 64911.450000 |
+--------------+
1 row in set (0.00 sec)
STRUCTURED QUERY LANGUAGE
Dual is a dummy table can be used for simple calculations

mysql> select 67*87 from dual;


+-------+
| 67*87 |
+-------+
| 5829 |
+-------+
1 row in set (0.04 sec)
mysql> select 1278653+098765 from dual;
+----------------+
| 1278653+098765 |
+----------------+
| 1377418 |
+----------------+
1 row in set (0.04 sec)
STRUCTURED QUERY LANGUAGE

mysql> select max(esal), min(esal),sum(esal),avg(esal),count(egender)


from employee;

+-----------+-----------+-----------+--------------+----------------+
| max(esal) | min(esal) | sum(esal) | avg(esal) | count(egender) |
+-----------+-----------+-----------+--------------+----------------+
| 86670.45 | 16670.45 | 649114.50 | 64911.450000 | 10 |
+-----------+-----------+-----------+--------------+----------------+
1 row in set (0.00 sec)
STRUCTURED QUERY LANGUAGE
For the purpose of display of annual salary the following command is used.

mysql> select eid, enm, esal, esal*12 as “ anual salary" from employee where
eid=1009;
mysql> select eid, enm, esal, esal*12 “ anual salary" from employee where
eid=1009;

+------+--------+----------+--------------+
| eid | enm | esal | anual salary |
+------+--------+----------+--------------+
| 1009 | rajesh | 26670.45 | 320045.40 |
+------+--------+----------+--------------+
1 row in set, 1 warning (0.00 sec)
STRUCTURED QUERY LANGUAGE

“like” operator is used in combination with wild card characters.


% stands for group of characters.
_ stands for single character.
mysql> select * from employee where enm like"s%";
+------+-----------+---------+----------+------------+------+
| eid | enm | egender | esal | doj | dno |
+------+-----------+---------+----------+------------+------+
| 1001 | sudhir | m | 55000.45 | 1968-08-25 | 10 |
| 1002 | sudhiksha | f | 65000.45 | 1999-08-25 | 20 |
+------+-----------+---------+----------+------------+------+
2 rows in set (0.00 sec)
STRUCTURED QUERY LANGUAGE

mysql> select * from employee where enm like"r_n%";


+------+------+---------+----------+------------+------+
| eid | enm | egender | esal | doj | dno |
+------+------+---------+----------+------------+------+
| 1010 | rani | f | 16670.45 | 2004-03-14 | 50 |
+------+------+---------+----------+------------+------+
1 row in set (0.00 sec)
• mysql> select * from employee where enm like
'ayush';
• +------+-------+---------+----------+------------+------+
• | eid | enm | egender | esal | doj | dno |
• +------+-------+---------+----------+------------+------+
• | 1008 | ayush | m | 86670.45 | 2002-04-14 |
40 |
• +------+-------+---------+----------+------------+------+
• 1 row in set (0.00 sec)
STRUCTURED QUERY LANGUAGE

mysql> select * from employee where enm like "s_d%";


+------+-----------+---------+----------+------------+------+
| eid | enm | egender | esal | doj | dno |
+------+-----------+---------+----------+------------+------+
| 1001 | sudhir | m | 55000.45 | 1968-08-25 | 10 |
| 1002 | sudhiksha | f | 65000.45 | 1999-08-25 | 20 |
+------+-----------+---------+----------+------------+------+
2 rows in set (0.00 sec)
STRUCTURED QUERY LANGUAGE
“group by” command is used to group all records as per the column specified and find max
, min, average, sum values.

select dno,max(esal), min(esal),avg(esal), sum(esal), count(esal) from employee group by


dno;
+------+-----------+-----------+--------------+-----------+-------------+
| dno | max(esal) | min(esal) | avg(esal) | sum(esal) | count(esal) |
+------+-----------+-----------+--------------+-----------+-------------+
| 10 | 55000.45 | 55000.45 | 55000.450000 | 55000.45 | 1|
| 20 | 65500.45 | 65000.45 | 65250.450000 | 130500.90 | 2|
| 60 | 85500.45 | 75000.45 | 80250.450000 | 160500.90 | 2|
| 40 | 86670.45 | 86500.45 | 86585.450000 | 173170.90 | 2|
| 30 | 86600.45 | 86600.45 | 86600.450000 | 86600.45 | 1|
| 50 | 26670.45 | 16670.45 | 21670.450000 | 43340.90 | 2|
+------+-----------+-----------+--------------+-----------+-------------+
6 rows in set (0.00 sec)
STRUCTURED QUERY LANGUAGE
In order to restrict tuples when group by clause is used , you cannot use
where for restricting rows. “having “ should be used for restricting tuples.
mysql> select dno,max(esal), min(esal),avg(esal), sum(esal), count(esal)
from employee group by dno having count(8)>=2;
+------+-----------+-----------+--------------+-----------+-------------+
| dno | max(esal) | min(esal) | avg(esal) | sum(esal) | count(esal) |
+------+-----------+-----------+--------------+-----------+-------------+
| 20 | 65500.45 | 65000.45 | 65250.450000 | 130500.90 | 2|
| 60 | 85500.45 | 75000.45 | 80250.450000 | 160500.90 | 2|
| 40 | 86670.45 | 86500.45 | 86585.450000 | 173170.90 | 2|
| 50 | 26670.45 | 16670.45 | 21670.450000 | 43340.90 | 2|
+------+-----------+-----------+--------------+-----------+-------------+
4 rows in set (0.00 sec)
STRUCTURED QUERY LANGUAGE
mysql> select curdate() from dual;
+------------+
| curdate() |
+------------+
| 2021-08-03 |
+------------+
1 row in set (0.01 sec)

mysql> select sysdate() from dual;


+---------------------+
| sysdate() |
+---------------------+
| 2021-08-03 10:47:51 |
+---------------------+
1 row in set (0.00 sec)
STRUCTURED QUERY LANGUAGE

mysql> select now() from dual;


+---------------------+
| now() |
+---------------------+
| 2021-08-03 10:48:56 |
+---------------------+
1 row in set (0.00 sec)
STRUCTURED QUERY LANGUAGE
“GROUP BY” clause is used when the user requires to find out max, min , avg, sum, count (aggregate
functions)values of a particular column where values are repeated by grouping them.

Only that column can be printed which ever is grouped.

IT is not possible to print the values of other columns.

mysql> select dno, max(esal), min(esal), count(esal), avg(esal), sum(esal) from employee group by dno;

+------+-----------+-----------+-------------+--------------+-----------+
| dno | max(esal) | min(esal) | count(esal) | avg(esal) | sum(esal) |
+------+-----------+-----------+-------------+--------------+-----------+
| 10 | 78665.89 | 55000.45 | 2 | 66833.170000 | 133666.34 |
| 20 | 65500.45 | 65000.45 | 2 | 65250.450000 | 130500.90 |
| 60 | 85500.45 | 75000.45 | 2 | 80250.450000 | 160500.90 |
| 40 | 87000.55 | 86500.45 | 3 | 86723.816667 | 260171.45 |
| 30 | 86600.45 | 86600.45 | 1 | 86600.450000 | 86600.45 |
| 50 | 26670.45 | 16670.45 | 2 | 21670.450000 | 43340.90 |
+------+-----------+-----------+-------------+--------------+-----------+
6 rows in set (0.09 sec)
STRUCTURED QUERY LANGUAGE
In order to restrict the display of the records after grouping them , the user has to
use “HAVING” clause.

“WHERE” clause will not work with the combination of grouping clause

mysql> select dno, max(esal), min(esal), count(esal), avg(esal), sum(esal) from


employee group by dno having dno=10;
+------+-----------+-----------+-------------+--------------+-----------+
| dno | max(esal) | min(esal) | count(esal) | avg(esal) | sum(esal) |
+------+-----------+-----------+-------------+--------------+-----------+
| 10 | 78665.89 | 55000.45 | 2 | 66833.170000 | 133666.34 |
+------+-----------+-----------+-------------+--------------+-----------+
1 row in set (0.02 sec)
STRUCTURED QUERY LANGUAGE

mysql> select dno, max(esal), min(esal), count(esal), avg(esal), sum(esal)


from employee group by dno having dno in(10,20);
+------+-----------+-----------+-------------+--------------+-----------+
| dno | max(esal) | min(esal) | count(esal) | avg(esal) | sum(esal) |
+------+-----------+-----------+-------------+--------------+-----------+
| 10 | 78665.89 | 55000.45 | 2 | 66833.170000 | 133666.34 |
| 20 | 65500.45 | 65000.45 | 2 | 65250.450000 | 130500.90 |
+------+-----------+-----------+-------------+--------------+-----------+
2 rows in set (0.04 sec)
STRUCTURED QUERY LANGUAGE

mysql> select dno, max(esal), min(esal), count(esal), avg(esal), sum(esal)


from employee group by dno having count(dno)<2;
+------+-----------+-----------+-------------+--------------+-----------+
| dno | max(esal) | min(esal) | count(esal) | avg(esal) | sum(esal) |
+------+-----------+-----------+-------------+--------------+-----------+
| 30 | 86600.45 | 86600.45 | 1 | 86600.450000 | 86600.45 |
+------+-----------+-----------+-------------+--------------+-----------+
1 row in set (0.02 sec)
STRUCTURED QUERY LANGUAGE

mysql> select dno, max(esal), min(esal), count(esal), avg(esal), sum(esal)


from employee group by dno having avg(esal) between 60000 and 70000;
+------+-----------+-----------+-------------+--------------+-----------+
| dno | max(esal) | min(esal) | count(esal) | avg(esal) | sum(esal) |
+------+-----------+-----------+-------------+--------------+-----------+
| 10 | 78665.89 | 55000.45 | 2 | 66833.170000 | 133666.34 |
| 20 | 65500.45 | 65000.45 | 2 | 65250.450000 | 130500.90 |
+------+-----------+-----------+-------------+--------------+-----------+
2 rows in set (0.04 sec)
STRUCTURED QUERY LANGUAGE

Distinct is used to eliminate duple values.


Distinct is used to display unique values.
mysql> select count(distinct(dno)) from employee;
+----------------------+
| count(distinct(dno)) |
+----------------------+
| 6|
+----------------------+
1 row in set (0.02 sec)
STRUCTURED QUERY LANGUAGE

delete command is used to delete all the records from the table.
But the table exists
mysql> delete from employee;

Delete command can delete a particular record based on the condition.


mysql> delete from employee where eid=1012;
STRUCTURED QUERY LANGUAGE

Update command is a DML command used to update the values of a


particular column

mysql> update employee


-> set esal=esal+100;
Query OK, 8 rows affected (0.17 sec)

mysql> update employee


-> set esal=esal+500
-> where eid=1008;
STRUCTURED QUERY LANGUAGE

mysql> update employee


-> set esal=esal+500
-> where esal between 86500 and 90000;
STRUCTURED QUERY LANGUAGE
mysql> select curdate();
+------------+
| curdate() |
+------------+
| 2021-08-05 |
+------------+
1 row in set (0.00 sec)

mysql> select now();


+---------------------+
| now() |
+---------------------+
| 2021-08-05 23:04:06 |
+---------------------+
1 row in set (0.00 sec)

mysql> select sysdate();


+---------------------+
| sysdate() |
+---------------------+
| 2021-08-05 23:04:14 |
+---------------------+
1 row in set (0.00 sec)
STRUCTURED QUERY LANGUAGE
mysql> select date(doj) from employee;
+------------+
| date(doj) |
+------------+
| 1968-08-25 |
| 1999-08-25 |
| 2001-06-25 |
| 2002-06-14 |
| 2002-07-14 |
| 2002-04-14 |
| 2001-04-14 |
| 2009-09-08 |
+------------+
8 rows in set (0.00 sec)

mysql> select month(doj) from employee;


+------------+
| month(doj) |
+------------+
| 8|
| 8|
| 6|
| 6|
| 7|
| 4|
| 4|
| 9|
+
STRUCTURED QUERY LANGUAGE
mysql> select year(doj) from employee;
+-----------+
| year(doj) |
+-----------+
| 1968 |
| 1999 |
| 2001 |
| 2002 |
| 2002 |
| 2002 |
| 2001 |
| 2009 |
+-----------+
8 rows in set (0.00 sec)
STRUCTURED QUERY LANGUAGE
mysql> SELECT SLEEP(2);
+----------+
| SLEEP(2) |
+----------+
| 0|
+----------+
1 row in set (2.11 sec)

mysql> SELECT NOW() SLEEP(5), NOW();


+----------+---------------------+
| SLEEP(5) | NOW() |
+----------+---------------------+
| 0 | 2021-08-05 23:11:17 |
+----------+---------------------+
1 row in set (5.01 sec)
STRUCTURED QUERY LANGUAGE
• -> select now(), sleep(6), sysdate()
• +---------------------+----------+---------------------+
• | now() | sleep(6) | sysdate() |
• +---------------------+----------+---------------------+
• | 2021-08-09 13:30:40 | 0 | 2021-08-09
13:30:46 |
STRUCTURED QUERY LANGUAGE
MATHEMATICAL FUNCTIONS:
mysql> SELECT MOD(11,4) AS "MODULUS";
+---------+
| MODULUS |
+---------+
| 3|
+---------+
1 row in set (0.02 sec)

mysql> SELECT POWER(3,2) AS "POWER";


+-------+
| POWER |
+-------+
| 9|
+-------+
1 row in set (0.06 sec)
STRUCTURED QUERY LANGUAGE
mysql> SELECT ROUND(123.456) AS "ROUND";
+-------+
| ROUND |
+-------+
| 123 |
+-------+
mysql> SELECT ROUND(456.789,2) AS "ROUND";
+--------+
| ROUND |
+--------+
| 456.79 |
+--------+
1 row in set (0.00 sec)
STRUCTURED QUERY LANGUAGE
mysql> SELECT SQRT(1.414) AS "SQUARE";
+------------------+
| SQUARE |
+------------------+
| 1.18911731969558 |
+------------------+
1 row in set (0.00 sec)

mysql> SELECT SQRT(144) AS "SQUARE";


+--------+
| SQUARE |
+--------+
| 12 |
+--------+
1 row in set (0.00 sec)
STRUCTURED QUERY LANGUAGE

mysql> SELECT TRUNCATE (1345.675,2) AS "TRUNCATE";


+----------+
| TRUNCATE |
+----------+
| 1345.67 |
+----------+
1 row in set (0.00 sec)
STRUCTURED QUERY LANGUAGE
STRING FUNCTIONS:-
mysql> SELECT LENGTH("RAMESHWARAM");
+-----------------------+
| LENGTH("RAMESHWARAM") |
+-----------------------+
| 11 |
+-----------------------+
1 row in set (0.00 sec)
mysql> SELECT TRIM(" rameshwaram ");
+--------------------------+
| TRIM(" rameshwaram ") |
+--------------------------+
| rameshwaram |
+--------------------------+
1 row in set (0.04 sec)
STRUCTURED QUERY LANGUAGE
mysql> SELECT UPPER("sudha");
+----------------+
| UPPER("sudha") |
+----------------+
| SUDHA |
+----------------+
1 row in set (0.02 sec)

mysql> select ucase("ram");


+--------------+
| ucase("ram") |
+--------------+
| RAM |
+--------------+
1 row in set (0.00 sec)
STRUCTURED QUERY LANGUAGE
mysql> select lcase("ram");
+--------------+
| lcase("ram") |
+--------------+
| ram |
+--------------+
1 row in set (0.00 sec)

mysql> select lower("ram");


+--------------+
| lower("ram") |
+--------------+
| ram |
+--------------+
1 row in set (0.00 sec)
STRUCTURED QUERY LANGUAGE
mysql> select substr("Excellent",2,5);
In the above command out of the string excellent , substring is extracted from 2 nd character .
From 2nd character it will extract 5 characters as specified in the parameters.

+-------------------------+
| substr("EXcellent",2,5) |
+-------------------------+
| Xcell |
+-------------------------+
1 row in set (0.00 sec)
mysql> select char(65,66,67,68)
-> ;
+--------------------------------------+
| char(65,66,67,68) |
+--------------------------------------+
| 0x41424344 |
+
STRUCTURED QUERY LANGUAGE
mysql> select concat(enm,egender) from employee;
+---------------------+
| concat(enm,egender) |
+---------------------+
| sudhirm |
| sudhikshaf |
| kiritt |
| mansif |
| nehalf |
| ayushm |
| rajeshm |
| pyushm |
+---------------------+
8 rows in set (0.00 sec)
STRUCTURED QUERY LANGUAGE
mysql> select employee.eid, employee.enm, department.dno, department.dnm from
employee , department where employee.dno=department.dno;
+------+---------------+-----+----------------------+
| eid | enm | dno | dnm |
+------+---------------+-----+----------------------+
| 1001 | ayan | 10 | computer department |
| 1003 | raju mahato | 10 | computer department |
| 1002 | tanmay mahato | 20 | physics department |
| 1004 | suraj | 30 | chemistry department |
| 1005 | nehaal | 30 | chemistry department |
| 1006 | meha | 40 | maths department |
| 1008 | XYZ | 50 | english department |
| 1012 | ramesh | 50 | english department |
| 1009 | saksham | 60 | sports department |
| 1010 | sejal | 70 | science department |
| 1011 | mehak | 70 | science department |
+------+---------------+-----+----------------------+
STRUCTURED QUERY LANGUAGE

mysql> select e.eid, e.enm, d.dno, d.dnm from employee e, department d


where e.dno=d.dno;

In the above command e is the alias name for employee and d is the alias
name for department.
STRUCTURED QUERY LANGUAGE

Select rows from table where a value is null;


mysql> select * from employee where ano is null;
+------+--------+---------+----------+------+------------+------+------------+
| eid | enm | egender | esal | ano | doj | dno | DOR |
+------+--------+---------+----------+------+------------+------+------------+
| 1011 | mehak | f | 82000.53 | NULL | 1998-11-22 | 70 | NULL |
| 1012 | ramesh | m | 88000.00 | NULL | 1995-06-02 | 50 | 2020-06-
02 |
STRUCTURED QUERY LANGUAGE
mysql> select * from employee where ano is not null;
+------+---------------+---------+----------+-------+------------+------+------+
| eid | enm | egender | esal | ano | doj | dno | DOR |
+------+---------------+---------+----------+-------+------------+------+------+
| 1001 | ayan |M | 75000.23 | 10001 | 1999-02-05 | 10 | NULL |
| 1002 | tanmay mahato | M | 72000.23 | 10002 | 1999-03-05 | 20 | NULL |
| 1003 | raju mahato | M | 72000.23 | 10003 | 1998-03-05 | 10 | NULL |
| 1004 | suraj |M | 73000.23 | 10004 | 1998-03-05 | 30 | NULL |
| 1005 | nehaal |f | 83000.23 | 10005 | 1998-03-05 | 30 | NULL |
| 1006 | meha |f | 85000.53 | 10006 | 1998-03-04 | 40 | NULL |
| 1008 | XYZ |f | 85000.53 | 10007 | 1997-03-05 | 50 | NULL |
| 1009 | saksham |m | 85000.53 | 10009 | 1996-12-05 | 60 | NULL |
| 1010 | sejal |f | 85000.53 | 10010 | 1994-12-22 | 70 | NULL |
+------
STRUCTURED QUERY LANGUAGE
The command to be used for displaying constraint name of the particular table.

mysql> select COLUMN_NAME, CONSTRAINT_NAME, REFERENCED_COLUMN_NAME, REFERENCED_TABLE_NAME


-> from information_schema.KEY_COLUMN_USAGE
-> where TABLE_NAME = 'employee';
+-------------+------------------+------------------------+-----------------------+
| COLUMN_NAME | CONSTRAINT_NAME | REFERENCED_COLUMN_NAME | REFERENCED_TABLE_NAME |
+-------------+------------------+------------------------+-----------------------+
| eid | PRIMARY | NULL | NULL |
| eid | PRIMARY | NULL | NULL |
| enm | enm | NULL | NULL |
| ano | ano | NULL | NULL |
| dept_no | employee_ibfk_1 | dept_no | dept |
| dept_no | employee_ibfk_2 | dept_no | dept |
| dno | employee_ibfk_4 | dno | department |
| dno | employee_ibfk_5 | dno | department |
| dno | employee_ibfk_6 | dno | department |
| dno | employee_ibfk_7 | dno | department |
| dno | employee_ibfk_8 | dno | department |
| dno | employee_ibfk_9 | dno | department |
| dno | employee_ibfk_10 | dno | department |
+-------------+------------------+------------------------+-----------------------+

You might also like