Professional Documents
Culture Documents
Unit3 Dbms
Unit3 Dbms
Content
BASICS OF DATABASE
MANAGEMENT SYSTEM
KOE-067
Unit: 3
Text books:
1. Elmasri, Navathe, “Fundamentals of Database System”,
Addision Wesley.
2. Korth, Silbertz, Sudarshan, “Database Concepts”, Mc Graw
Hill.
3. Bipin C. Desai, “An Introduction to Database System”,
Galgotia Publication.
4. Majumdar & Bhattacharya, “Database Management System”,
McGraw Hill.
5. Date C.J., “An Introduction to Database System”, Addision
Wesley.
• Program Outcomes are narrow statements that describe what the students
are expected to know and would be able to do upon the graduation.
• These relate to the skills, knowledge, and behavior that students acquire
through the programmed.
1. Engineering knowledge
2. Problem analysis
3. Design/development of solutions
4. Conduct investigations of complex problems
5. Modern tool usage
6. The engineer and society
7. Environment and sustainability
8. Ethics
9. Individual and team work
10. Communication
11. Project management and finance
12. Life-long learning
05/07/2024 Mr. Manish Kumar KOE-067 Unit-3 11
CO-PO Mapping
Content
CO.K PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
KOE 067.1 2 2 3 3 3 2 3 2 2 2 2 3
KOE 067.2 3 3 3 2 2 2 2 2 2 2 2 3
KOE 067.3
2 3 3 3 3 2 2 2 2 2 2 2
KOE 067.4
2 3 2 2 2 2 2 2 2 3 2 2
KOE 067.5
2 3 2 2 2 3 2 2 3 2 2 2
• Program Specific Outcomes (PSOs) are what the students should be able to do
at the time of graduation. The PSOs are program specific. PSOs are written by
the department offering the program. On successful completion of B. Tech. (EC)
Program, the Electronics and Communication engineering graduates will be able
to:
PSO1: To apply the knowledge of mathematics, science and electronics &
communication engineering to work effectively in the industry based on
same or related area.
PSO2: To use their skills to work in modern electronics & communication
engineering tools, software and equipments to design solutions for complex
problems in the related field that meet the specified needs of the society.
PSO3: To function effectively as an individual and as a member or leader of a team
by qualifying through examinations like GATE (Graduate Aptitude Test in
Engineering), IES (Indian Engineering Services), PSUs (Public Sector
Undertakings), TOEFL (Test of English as a Foreign Language), GMAT
(Graduate Management Admission Test) and GRE (Graduate Record
Examinations in US) etc.
• The Program Educational Objectives (PEOs) of an engineering degree program are the
statements that describe the expected achievements of graduates in their career, and what the
graduates are expected to perform and achieve during the first few years after graduation.
PEO3: To effectively bridge the gap between industry and academics through effective
communication skill, professional attitude and a desire to learn.
UNIT 3
Structured Query Language (SQL): Basics of SQL, DDL, DML, DCL,
advantage of SQL, SQL data type and literals, types of SQL commands,
SQL operators and their procedure, tables –creation & alteration, defining
constraints, views and indexes, queries and sub queries ,aggregate
functions, built-in functions, insert, update and delete operations, joins,
unions,intersection, minus, transaction control commands.
PL/SQL: Introduction, features, syntax and constructs, SQL within Pl/SL,
DML in PL/SQL Cursors, stored procedures, stored function, database
triggers, indices
Advantages of SQL –
1. High speed
Using the SQL queries, the user can quickly and efficiently retrieve a
large amount of records from a database.
2. No coding needed
In the standard SQL, it is very easy to manage the database system.
It doesn't require a substantial amount of code to manage the
database system.
3. Well defined standards
Long established are used by the SQL databases that are being used
by ISO and ANSI.
4. Portability
SQL can be used in laptop, PCs, server and even some mobile
phones.
5. Interactive language
SQL is a domain language used to communicate with the database.
It is also used to receive answers to the complex questions in
seconds.
6. Multiple data view
Using the SQL language, the users can make different views of the
database structure.
EX-
Table 1 shows the relational database with name STUDENT.
STUDENT
ROLL_NO NAME ADDRESS PHONE AGE
1 RAM DELHI 1234567 18
2 RAMESH GURGAON 456789 18
3 SUJIT ROHTAK 567891 20
4 SURESH DELHI 145867 17
ROLL_NO NAME
3 SUJIT
4 SURESH
• There are five types of SQL commands: DDL, DML, DCL, TCL, and DQL.
SYNTAX-
CREATE TABLE table_name
(Column1 datatype(size),
Column2 datatype(size),
……..
Column100datatype(size) );
Eg-
CREATE TABLE students
(
ROLL_NO int(3), NAME varchar(20), SUBJECT varchar(40)
);
c) ALTER –
• This is command used to alter the structure of the database.
• Used to add, delete/drop, modify columns in existing database.
SYNTAX-
d) TRUNCATE–
• This command is used to delete complete data from an existing
table..
SYNTAX-
TRUNCATE TABLE table_name;
a) INSERT –
SYNTAX-
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
b) UPDATE –
It is used to modify the existing records in a table.
SYNTAX-
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
c) DELETE –
It is used to delete the existing records in a table.
SYNTAX-
DELETE FROM table_name WHERE condition;
Where,
• privilege names are SELECT,UPDATE,DELETE,INSERT,ALTER,ALL
• objectname is table name
• user is the name of the user to whom we grant privileges
SYNTAX-
REVOKE privlege_name on objectname from user;
Where,
• privilege names are SELECT,UPDATE,DELETE,INSERT,ALTER,ALL
• objectname is table name
• user is the name of the user whose privileges are removing
Binary Datatypes
SQL_operators
QUERY-
SELECT * FROM Employee_details WHERE Emp_Salary != 25000;
SYNTAX
SELECT column_Name1, ...., column_NameN FROM table_Name
WHERE column Comparison_operator ALL (SELECT column FROM table
name2)
QUERY-
SELECT Emp_Id, Emp_Name FROM Employee_details WHERE Emp_
Salary > ALL ( SELECT Emp_Salary FROM Employee_details WHERE
Emp_City = Jaipur)
SYNTAX
SELECT column1, ...., columnN FROM table_Name WHERE condition
1 AND condition2 AND condition3 AND ....... AND conditionN;
QUERY-
SELECT * FROM Employee_details WHERE Emp_Salary = 25000 AND
Emp_City = 'Delhi';
QUERY
SELECT * FROM Employee_details WHERE Emp_Salary BETWEEN 30
000 AND 45000;
SYNTAX
SELECT column_Name1, column_Name2 ...., column_NameN FROM
table_Name WHERE column_name IN (list_of_values);
QUERY-
SELECT * FROM Employee_details WHERE Emp_Id IN (102, 103, 104
);
SYNTAX
SELECT column1, column2 ...., columnN FROM table_Name WHERE
column_name comparison_operator ANY ( SELECT column_name F
ROM table_name WHERE condition(s)) ;
QUERY-
SELECT * FROM Employee_details WHERE Emp_Name LIKE ’r%' ;
QUERY-
SELECT * FROM Employee_details WHERE Emp_Name LIKE ’%j' ;
SYNTAX-
CREATE DATABASE database_name;
Eg-
CREATE DATABASE my_database;
SYNTAX-
CREATE TABLE table_name
(Column1 datatype(size),
Column2 datatype(size),
……..
Column100datatype(size) );
Eg-
CREATE TABLE students
(
ROLL_NO int(3), NAME varchar(20), SUBJECT varchar(40)
);
Example-
Create a table called “Persons” that contains five columns:
PeronID, LastName, FirstName, Address, City;
Example-
Create a new table called “Testtables” which I a copy of the
‘customer’
ALTER –
• This is command used to alter the structure of the database.
• Used to add, delete/drop, modify columns in existing database.
ALTER TABLE Student RENAME COLUMN NAME TO FIRST_NAME;
• ALTER TABLE – ADD
- used to add columns into the existing table
SYNTAX-
Example-
Add an “email” column to the “customers” table.
SYNTAX-
Example-
Delete an “email” column from the “customers” table.
Example:
• Specifying a default manager for a new department and a default
department for a new employee.
Example:
Dnumber INT NOT NULL CHECK (Dnumber > 0 AND Dnumber < 21);
• The CHECK clause can also be used in conjunction with the CREATE
DOMAIN statement.
Example:
we can write the following statement:
CREATE DOMAIN D_NUM AS INTEGER
CHECK (D_NUM > 0 AND D_NUM < 21);
Mr. Manish Kumar KOE-067 Unit-3
05/07/2024 101
Content
Specifying Constraints in SQL
SQL Server:
DROP INDEX table_name.index_name;
MySQL:
ALTER TABLE table_name
DROP INDEX index_name;
SYNTAX-
COUNT(*)
or
COUNT( [ALL|DISTINCT] expression )
• QUERY 2
SELECT COUNT(*)
FROM PRODUCT_MAST;
WHERE RATE>=20;
• QUERY 3
SELECT COUNT(DISTINCT COMPANY)
FROM PRODUCT_MAST;
SYNTAX-
SUM ()
or
SUM ( [ALL|DISTINCT] expression )
• QUERY 2
SELECT SUM(COST)
FROM PRODUCT_MAST
WHERE QTY>3;
SYNTAX-
AVG ()
or
AVG ( [ALL|DISTINCT] expression )
SYNTAX-
MAX ()
or
MAX ( [ALL|DISTINCT] expression )
Output = ???
SYNTAX-
MIN ()
or
MIN ( [ALL|DISTINCT] expression )
Output = ???
Where-
table1: First table.
table2: Second table
matching_column: Column common to both the tables.
SYNTAX –
Where-
table1: First table.
table2: Second table
matching_column: Column common to both the tables.
SYNTAX –
SELECT Student.NAME,StudentCourse.COURSE_ID
FROM Student
LEFT JOIN StudentCourse
ON StudentCourse.ROLL_NO = Student.ROLL_NO;
Where-
table1: First table.
table2: Second table
matching_column: Column common to both the tables.
SYNTAX –
SELECT Student.NAME,StudentCourse.COURSE_ID
FROM Student
RIGHT JOIN StudentCourse
ON StudentCourse.ROLL_NO = Student.ROLL_NO;
Where-
table1: First table.
table2: Second table
matching_column: Column common to both the tables.
SYNTAX –
SELECT Student.NAME,StudentCourse.COURSE_ID
FROM Student
FULL JOIN StudentCourse
ON StudentCourse.ROLL_NO = Student.ROLL_NO;
SQL PL/SQL
SQL is a single query that is used to PL/SQL is a block of codes that used
perform DML and DDL operations. to write the entire program blocks/
procedure/ procedure, etc.
DECLARE
declaration statements;
BEGIN
executable statements
EXCEPTIONS
exception handling statements;
END;
2. Execution section:
• Execution section starts with BEGIN keyword and ends with END
keyword.
• It is a mandatory section.
• It is used to write the program logic code.
1. Variables:
• Like several other programming languages, variables in PL/SQL
must be declared prior to its use. They should have a valid name
and data type as well.
• Syntax for declaration of variables:
SQL> DECLARE
var1 INTEGER;
var2 REAL;
var3 varchar2(20) ;
BEGIN
null;
END;
/
OUTPUT- PL/SQL procedure successfully completed.
BEGIN
null;
END;
/
BEGIN
dbms_output.put_line(var);
END;
/
OUTPUT – Hello World
• dbms_output.put_line : This command is used to direct the
PL/SQL output to a screen.
BEGIN
dbms_output.put_line(var);
END;
/
SQL> DECLARE
BEGIN
null;
END;
/
%FOUND
Returns TRUE if an INSERT, UPDATE, or DELETE statement affected
one or more rows or a SELECT INTO statement returned one or more
rows. Otherwise, it returns FALSE.
%NOTFOUND
The logical opposite of %FOUND.
It returns TRUE if an INSERT, UPDATE, or DELETE statement
affected no rows, or a SELECT INTO statement returned no rows.
Otherwise, it returns FALSE.
%ISOPEN
Always returns FALSE for implicit cursors, because Oracle closes the
SQL cursor automatically after executing its associated SQL
statement.
%ROWCOUNT
Returns the number of rows affected by an INSERT, UPDATE, or
DELETE statement, or returned by a SELECT INTO statement.
DECLARE
declaration statements;
BEGIN
executable statements
EXCEPTIONS
exceptionhandling statements
END;
Mr. Manish Kumar KOE-067 Unit-3
05/07/2024 166
PL/SQL identifiers
Content (CO3)
BEGIN
null;
END;
/
• Example:
create table branch
(branch_name char(15) not null,
branch_city char(30),
assets integer)
• not null
• primary key (A1, ..., An )
– Ai represents an attribute
– Ri represents a relation
– P is a predicate.
• This query is equivalent to the relational algebra expression.
7. Anomalies are avoided by splitting the offending relation into multiple relations, is also known as
a) Accupressure
b) Decomposition
c) Precomposition
d) Both Decomposition and Precomposition
8. Every time attribute A appears, it is matched with the same value of attribute B, but not the same value of attribute
C. Therefore, it is true that:
a) A -> B
b) A -> C
c) A -> (B,C)
d) (B,C) -> A
9. When the values in one or more attributes being used as a foreign key must exist in another set of one or more
attributes in another table, we have created a(n):
a) Transitive Dependency
b) Insertion Anomaly
c) Referential Integrity Constraint
d) Normal Form
05/07/2024 Mr. Manish Kumar KOE-067 Unit-3 180
MCQ
Content
190
05/07/2024 Mr. Manish Kumar KOE-067 Unit-3
RecapContent
of Unit-3
Text books:
1. Elmasri, Navathe, “Fundamentals of Database System”,
Addision Wesley.
2. Korth, Silbertz, Sudarshan, “Database Concepts”, Mc Graw
Hill.
3. Bipin C. Desai, “An Introduction to Database System”,
Galgotia Publication.
4. Majumdar & Bhattacharya, “Database Management System”,
McGraw Hill.
5. Date C.J., “An Introduction to Database System”, Addision
Wesley.