MATRUSRI ENGINEERING COLLEGE�DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
SUBJECT NAME: DataBase Management Systems
FACULTY NAME: K Sunil Manohar Reddy
Insert Your Photo here🡪
MATRUSRI
ENGINEERING COLLEGE
INTRODUCTION: ��THIS UNIT DEALS WITH THE ADVANCED SQL AND ALSO EMBEDDED SQL AND DYNAMIC SQL.
UNIT-III
OUTCOMES:
Upon completion of this unit, student will be able to:
MATRUSRI
ENGINEERING COLLEGE
CONTENTS:� ADVANCED SQL: SQL DATA TYPES AND SCHEMES, INTEGRITY CONSTRAINTS, AUTHORIZATION, EMBEDDED SQL, DYNAMIC SQL, FUNCTIONS AND PROCEDURAL CONSTRUCTS, RECURSIVE QUERIES, ADVANCED SQL FEATURES ��
OUTCOMES:
Upon completion of this module, student will be able to:
MODULE-I
MATRUSRI
ENGINEERING COLLEGE
Transactions
MATRUSRI
ENGINEERING COLLEGE
Built-in Data Types in SQL
MATRUSRI
ENGINEERING COLLEGE
Index Creation
create table student �(ID varchar (5),�name varchar (20) not null,�dept_name varchar (20),�tot_cred numeric (3,0) default 0,�primary key (ID))
create index studentID_index on student(ID)
Indices are data structures used to speed up access to records with specified values for index attributes
e.g. select * � from student� where ID = ‘12345’
can be executed by using the index to find the required record, without looking at all records of student
MATRUSRI
ENGINEERING COLLEGE
Integrity Constraints
Constraints on a Single Relation
MATRUSRI
ENGINEERING COLLEGE
Not Null & Unique Constraints
name varchar(20) not null� budget numeric(12,2) not null
MATRUSRI
ENGINEERING COLLEGE
The check clause
create table section
(course_id varchar (8),
sec_id varchar (8),
semester varchar (6),
year numeric (4,0),
building varchar (15),
room_number varchar (7),
time slot id varchar (4),
primary key (course_id, sec_id, semester, year),
check (semester in ('Fall', 'Winter', 'Spring', 'Summer')))
MATRUSRI
ENGINEERING COLLEGE
Authorization
MATRUSRI
ENGINEERING COLLEGE
Authorization Specification in SQL
grant <privilege list>on <relation name or view name> to <user list>
MATRUSRI
ENGINEERING COLLEGE
Revoking Authorization in SQL
MATRUSRI
ENGINEERING COLLEGE
Embedded SQL
EXEC SQL <embedded SQL statement >;
Note: this varies by language:
�
MATRUSRI
ENGINEERING COLLEGE
Embedded SQL (Cont.)
EXEC-SQL connect to server user user-name using password;
Here, server identifies the server to which a connection is to be established.
EXEC-SQL BEGIN DECLARE SECTION}
int credit-amount ;
EXEC-SQL END DECLARE SECTION;
declare c cursor for <SQL query>
statement. The variable c is used to identify the query
MATRUSRI
ENGINEERING COLLEGE
Functions and Procedures
MATRUSRI
ENGINEERING COLLEGE
Declaring SQL Functions
create function dept_count (dept_name varchar(20))� returns integer� begin� declare d_count integer;� select count (* ) into d_count� from instructor� where instructor.dept_name = dept_name� return d_count;� end
MATRUSRI
ENGINEERING COLLEGE
Declaring SQL Functions
create function dept_count (dept_name varchar(20))� returns integer� begin� declare d_count integer;� select count (* ) into d_count� from instructor� where instructor.dept_name = dept_name� return d_count;� end
select dept_name, budget� from department� where dept_count (dept_name ) > 12
MATRUSRI
ENGINEERING COLLEGE
SQL Procedures
create procedure dept_count_proc (in dept_name varchar(20), � out d_count integer)� begin
select count(*) into d_count� from instructor� where instructor.dept_name = dept_count_proc.dept_name
end
declare d_count integer;� call dept_count_proc( 'Physics', d_count); Procedures and functions can be invoked also from dynamic SQL
MATRUSRI
ENGINEERING COLLEGE
Recursive Queries
This example view, rec_prereq, is called the transitive closure of the prereq relation
MATRUSRI
ENGINEERING COLLEGE
The Power of Recursion
MATRUSRI
ENGINEERING COLLEGE