Database Management System
Database Management System
Assignment 1
Ans. Structured Query Language (SQL) is a specialized language for updating, deleting, and
requesting information from databases. SQL is an ANSI and ISO standard, and is the de facto
standard database query language. A variety of established database products support SQL,
including products from Oracle and Microsoft SQL Server. It is widely used in both industry and
academia, often for enormous, complex databases.
(i) SQL enables end user and system persons to deal with a number of database management
systems where it is available.
(ii) Applications written in SQL can be easily ported across systems. Such porting could be required
when the underlying DBMS needs to upgraded because of change in transaction volumes or
when a system developed in one environment is to be used on another.
(iii)SQL as a language is independent of the way it is implemented internally. A query returns the
same result regardless of whether optimizing has been done with indexes or not. This is because
SQL specifies what is required and not how it is to be done.
(iv) The language while being simple and easy to learn can cope with complex situations.
(v) The results to be expected are well defined in SQL.
3. Create table student with fields: Roll No. , Name, Course and Date of Birth and display its
structure.
Query:-
Roll_Noint,
Name varchar(20),
Course varchar(10),
DOB date)
Screenshot:-
4. Modify the structure of student table as follows(display structure after every modification):
a. Add two new columns named Section and Contact No.
Query:-
ALTER table student_09990302012 ADD(Section char(10),Contact_Noint)
Screenshot:-
Screenshot:-
Screenshot:-
Query:-
Desc student_09990302012
Screenshot:-
Desc student_09990302012
5. Create table Employee with fields: EmpID, EmpName, Designation and Date of Joining
Query:-
Emp_IDint,
Emp_Namevarchar(20),
Designation varchar(15),
DOJ date)
Screenshot:-
6. Modify the structure of Employee table as follows(display structure after every modification):
a. Add a new column Salary.
Query:-
ALTER table Employ_09990302012 ADD(Salary int)
Screenshot:-
Screenshot:-
Query:-
DESC Employ_09990302012
Screenshot:-
DESC Employ_09990302012
Assignment 2
Commands Used: Create, Select with where clause, Rename, Delete and
1. What is a DML command? Explain with examples the different types of DML commands?
Ans.A Data Manipulation Language (DML) is a family of syntax elements similar to a
computer programming language used for inserting, deleting and updating data in a database.
Performing read-only queries of data is sometimes also considered a component of DML. Data
manipulation language comprises the SQL data change statements, which modify stored data but
not the schema or database objects. Manipulation of persistent database objects, e.g., tables or
stored procedures, via the SQL schema statements, rather than the data stored within them, is
considered to be part of a separate data definition language. In SQL these two categories are
similar in their detailed syntax, data types, expressions etc., but distinct in their overall function.
Data Manipulation Language (DML) statements are used for managing data within schema
objects. Some examples:
The logical operators AND, OR, and NOT operate according to the value returned by the truth
table. AND & OR are binary operators; NOT is a unary operator.
Relational operators
Relational operators are =,! =, <, >, <=, and >=. They allow for arbitrary comparisons of
complex expressions.
Screenshot:-
DESC Customer_09990302012;
4. Insert 5 rows each using all the three methods(All Fields, Selected Fields and User interactive)
Query:-
All Fields
insert into Customer_09990302012 values
(101,'Rahul','Kumar','New Delhi','Delhi',990062)
Selected Field
(106,'Raj','Veer')
User interactive
Old 1: insert into Customer_09990302012 values
(&Customer_ID ,'&FName','&LName','&City','&State',&Pin)
New 1: insert into Customer_09990302012 values
(100 ,'Himanshu','Gautam','New Delhi','Delhi',990006)
Query:-
Select * from Customer_09990302012
Screenshot:-
Screenshot:-
Screenshot:-
8. Display all records from the customer table where state is Delhi
Query:-
Select * from Customer_09990302012 where (state = 'Delhi')
Screenshot:-
9. Display fname,lname of customers concatenated with state and name it as “Customer and their
Location”.
Query:-
Select FName || LName || State as Customer from Customer_09990302012;
Screenshot:-
10. Display the records of those customers whose pin is not entered.
Query:-
Select * from customer_09990302012 where PIN is Null
Screenshot:-
Screenshot:-
Screenshot:-
Screenshot:-
Screenshot:-
Screenshot:-
Screenshot:-
17. Retrieve all rows where CID is between 100 and 108 (both numbers included)
Query:-
SelectCustomer_ID from Customer_09990302012 whereCustomer_IDBetween 100 AND 108
Screenshot:-
18. Display those rows where state name begins with ‘D’
Query:-
Select State from Customer_09990302012 where state LIKE 'D%'
Screenshot:-
19. Retrieve all rows where first name contains the word ‘RAJ’
Query:-
Select FName from Customer_09990302012 whereFName LIKE 'Raj%'
Screenshot:-
20. Retrieve all rows where name field contains the word’RA ESH’
Query:-
Select FName from Customer_09990302012 whereFName LIKE '%Ra_esh%'
Screenshot:-
Screenshot:-
Assignment 3
1. Create table employee____ with following attributes: empid, fname, lname, bdate, address,
gender, salary,dept No..
Query:-
Create table
Employ_09990302012(Emp_IDint,Dept_Noint,FNamevarchar(20),LNamevarchar(20),DOB
Varchar(20),Address varchar(20),Gender Char(5),Salary int)
Query:-
DESC Employ_09990302012
Screenshot:-
Select * from Cust_09990302012
DESC Employ_09990302012
4. Find names and salary of all the employees sorted according to their salary (ascending as well as
descending).Ascending By Default
Query:-
select * from employ_09990302012 order by Salary
Screenshot:-
Query:-
select * from employ_09990302012 order by Salary DESC
Screenshot:-
5. List names of employees having salary between 10,000 and 20,000 using logical operators
Query:-
Select * from employ_09990302012 where SalaryBetween 10000 and 20000
Screenshot:-
9. List all those employees whose first name is “Ram” and last Name is “Kapoor”.
Query:-
Select * from employ_09990302012 where Fname = 'Ram' And Lname = 'Kapoor'
Screenshot:-
Screenshot:-
Query:-
Select * from employ_09990302012
Screenshot:-
Query:-
Select * from employ_09990302012
Screenshot:-
Query:-
Select * from employ_09990302012
Screenshot:-
Assignment 4
1. What are the grouping functions and how do you define the different grouping
functions(min,max,count,avg,sum)
Ans. Group functions are built-in SQL functions that operate on groups of rows and return one
value for the entire group. These functions are: COUNT, MAX, MIN, AVG, SUM, DISTINCT
GROUP BY will aggregate records by ORDER BY alters the order in which items
the specified column which allows you are returned. It can order the items either in
to perform aggregation functions on ascending or in descending order.
non-grouped columns (such as SUM,
COUNT, AVG, etc.).
DESC Employee_09990302012
Query:-
Screenshot:-
Screenshot:-
Screenshot:-
Screenshot:-
15. Update the commission to 10%of salary for all the employees having salary greater than 50000.
Query:-
17. Update the salaries of all employees in marketing department by hiking it by 15%.
Query:-
18. Find out the difference between highest and lowest salaries for each department.
Query:-
select max(salary),min(salary) from Employee_09990302012 Group by dept_no
Screenshot:-
19. List average salary for all the departments which have more than 5 People.
Query:-
20. List jobs of all the employees where maximum salary is greater than or equal to 40000
Query:-
21. List jobs and no. of employees in each job. The result should be in descending order of the
number of employees
Query:-
23. List total, Max, Min, Average salary of employees job wise for dept no 2 and display only those
with average salary >10000
Query:-
Practice Question - 1
1. Create a table employee with the following fields:
empno,ename,salary,commission,job,department number.
Query:-
DESC emp_09990302012
Screenshot:-
DESC emp_09990302012
Query:-
select * from emp_09990302012
Screenshot:-
4. Give an alias name to 5% of salary and display empno,ename,salary and the alias name
HRA.Query:-
selectEno,Ename,Salary, (.05 * Salary) as "HRA" From emp_09990302012
Screenshot:-
7. Find out the maximum salary of the department where the maximum salary should be more than
30000.
Query:-
select MAX(Salary),Dept_no from emp_09990302012
group by dept_no having MAX(Salary)>30000
Screenshot:-
8. Find out the number of employees in each department in their ascending order of the number for
those department where atleast two employees work and that two in department 10.20,30.
Query:-
select count(*),Dept_no from emp_09990302012 where dept_no IN (10,20,30)
group by dept_no having count(*)>2 order by count(*) DESC
Screenshot:-
Assignment 5
Key constraints
Ans.SQL constraints are defined as the limitations that are used to limit the type of data that can
be added into a table.
Constraints can be specified at two levels :
o Table level constraints, and
o Column level constraints
Table Level Constraints are applied by the DBA whereas;The Column Level
constraints can be added after the table is created.
The SQL constraints can be applied using Create Table Command and Alter Table
Command
2. What are the different types of SQL constraints? Explain each in detail:
Ans.
Not null:The NOT NULL constraint enforces a column to NOT accept NULL values.
SYNTAX:
create table course_a023
(code number(10) primary key,namevarchar(10) not null,sectionvarchar(5))
Unique: The UNIQUE constraint uniquely identifies each record in a database table. The
UNIQUE and PRIMARY KEY constraints both provide a guarantee for uniqueness for a
column or set of columns. A PRIMARY KEY constraint automatically has a UNIQUE
constraint defined on it.
SYNTAX:
Check: The CHECK constraint is used to limit the value range that can be placed in a
column.
SYNTAX:
Create table person
(P_idnumber(10),Check (p_id>0))
Default: The DEFAULT constraint is used to insert a default value into a column.
SYNTAX:
Create table person
(P_idnumber(10) not null,Cityvarchar(20) default ‘delhi’)
Primary key: The PRIMARY KEY constraint uniquely identifies each record in a
database table. Primary keys must contain unique values. A primary key column cannot
contain NULL values.
SYNTAX:
Create table person
(P_idnumber(10) not null primary key,Cityvarchar(20) default ‘delhi’)
Foreign key: A FOREIGN KEY in one table points to a PRIMARY KEY in another
table.
SYNTAX:
PERSON TABLE
ORDER TABLE
Here the primary key of person table is assigned as foreign key in the order table.
3.
a) create table course___ with fields: coursecode(primary key), coursename(not
null),section.
Query:-
create table course_09990302012(course_codeint primary key,course_namevarchar(20)
not null,Sectionvarchar(20))
Query:-
desc course_09990302012
Screenshot:-
desc course_09990302012
b) create table student___ with following attributes rollno, last name, first name,
address(unique), coursecode(foreign key)
Query:-
create tables student_09990302012(
Roll_Noint,Fnamevarchar(20),Lnamevarchar(20),Address
varchar(20)unique,Course_codeint,constraint Ass5 foreign key(Course_code) references
course_09990302012 (Course_code))
Query:-
desc Student_09990302012
Screenshot:-
desc Student_09990302012
Query:-
desc Student_09990302012
Screenshot:-
desc Student_09990302012
Query:-
desc Student_09990302012
Screenshot:-
desc Student_09990302012
Screenshot:-
Query:-
desc Student_09990302012
Screenshot:-
desc Student_09990302012
4.
Person table
p_id lastname firstname address city
Orders table:
o_id orderno p_id
1 77895 3
2 44678 3
3 22456 2
4 24562 1
Query:-
Query:-
Screenshot:-
Query:-
Query:-
Screenshot:-
Query:-
Screenshot:-
Query:-
Screenshot:-
Query:-
Screenshot:-
4) Tryto delete a record from person table and find out the result
Query:-
Screenshot:-
5)Try to delete a record from order table and find out the result.
Query:-
Screenshot:-
To solve this problem we use the word “on delete cascade” whereis used along with
child table so that the records can be deleted from directly from the parent table.
Assignment 6
Ans.A scalar function is a function that, for each set of one or more scalar parameters,
returns a single scalar value. Examples of scalar functions include the LENGTH function,
and the SUBSTR function. Scalar functions can also be created that do complex
mathematical calculations on function input parameters. Scalar functions can be referenced
anywhere that an expression is valid within an SQL statement, such as in a select-list, or in a
FROM clause.
Some of the scalar functions are:
o Absolute
o Length
o Upper
o Lower
o Ceil
o Floor
o Susbstr
o Instr
o Initcap
o Round, etc
3. Give Syntax and Queries to demonstrate the use of following Numeric functions in System
Defined Table.
a. Absolute
Query:-
Select abs (-13.5) from dual
Screenshot:-
b. Ceil
Query:-
Select ceil (3.5) from dual
Screenshot:-
c. Floor
Query:-
Select floor(13.5) from dual
Screenshot:-
d. Round
Query:-
Select round(13.52,1) from dual
Screenshot:-
e. Mod
Query:-
Select mod (3,5) from dual
Screenshot:-
f. Power
Query:-
Select power(3,5) from dual
Screenshot:-
g. Tan
Query:-
Select tan(5) from dual
Screenshot:-
h. Log
Query:-
Select log (3,10) from dual
Screenshot:-
i. Cos
Query:-
Select cos (15) from dual
Screenshot:-
j. Sin
Query:-
Select sin(13) from dual
Screenshot:-
k. Trunc
Query:-
Select trunc (13.235,2) from dual
Screenshot:-
l. Greatest
Query:-
Select greatest(1,3,5) from dual
Screenshot:-
m. Least
Query:-
Select least(1,3,5) from dual
Screenshot:-
n. Sqrt
Query:-
Select sqrt(13) from dual
Screenshot:-
2. Create the following table and perform the below mentioned Queries
A B C
-12.5 2 3
-13.5 4 5
0.5 6 7
1.0 8 9
2.0 10 99
Query:-
Create table arth09990302012( A number(4,2),B int,Cint)
Query:-
select * from arth09990302012;
Screenshot:-
b. Find the upper and lower values of Column A and column B respectively.
Query:-
select ceil(A),ceil(B),floor(A),floor(B) from arth09990302012;
Screenshot:-
c. Find the Power value using Absolute A as base and column C as its power.
Query:-
select power(abs(A),c) from arth09990302012;
Screenshot:-
3. Give Syntax and Queries to demonstrate the use of following Character functions in
System Defined Table
a. Initcap
Query:-
Select initcap('Rakesh') from dual
Screenshot:-
b. Length
Query:-
Select length('Rakesh') from dual
Screenshot:-
c. Substr
Query:-
Select substr('RyuLove',4,4) from dual
Screenshot:-
d. Instr
Query:-
Select instr('Rakesh','a') from dual
Screenshot:-
e. Trim
Query:-
select trim(both 'u' from 'Rayu') from dual
Screenshot:-
f. Ltrim
Query:-
selectltrim('Ryu Love','Ryu') from dual
Screenshot:-
g. Rtrim
Query:-
Select rtrim('RyuLove','Love') from dual
Screenshot:-
h. Lpad
Query:-
Select lpad('Ryu',10,'*****') from dual
Screenshot:-
i. Rpad
Query:-
Select rpad('Ryu',10,'*****') from dual
Screenshot:-
j. Upper
Query:-
Select upper('rakesh') from dual
Screenshot:-
k. Lower
Query:-
Select lower('RAKESH') from dual
Screenshot:-
l. Replace
Query:-
select replace('R','R','Ryu') from dual
Screenshot:-
m. Translate
Query:-
select translate('rakesh','a','A') from dual
Screenshot:-
4. Create the following table and perform the below mentioned Queries
Eid Ename Designation Salary City
101 Rajiv Manager 10000 Delhi
102 Sita Clerk 5000 Mumbai
103 Ram Manager 10000 Chennai
104 Ramesh Assistant 8000 Hyderabad
105 Shyam Clerk 5000 Delhi
Query:-
create table scemp_09990302012 (Eidint,Enamevarchar(20),Designation varchar(20),Salary
int,Cityvarchar(20))
Query:-
select * from scemp_09990302012
Screenshot:-
Assignment 7
Date functions
1. What are date functions?
Ans. A data function is use to manipulate and extract the data from a particular column. A
date function will accept data as a input.
a. Add_months(d,n) :This function will return specify date after adding the number of
months to the date mention.
b. Last_day(d) : This function return the last date of the month specified in the function.
c. Months between (d2, d1): This function will return the number of months between the
D2 , D1.
d. Next_day(d,day) : This function will return the date of the first week i.e. is mention by
the day in the function.
2. Give Syntax and Queries to demonstrate the use of following Date functions in System
Defined Table
a. Add_months(d,n)
Query:-
Select add_months('99-mar-2013',3) from dual
Screenshot:-
b. Last_day(d)
Query:-
Select last_day('99-mar-2013') from dual
Screenshot:-
c. Months_between(d2,d1)
Query:-
Select Months_between('99-mar-2013','99-feb-2013') from dual
Screenshot:-
d. Next_day(d,day)
Query:-
Select Next_day('99-mar-2013','Mon') from dual
Screenshot:-
Query:-
a. Increase End date by 3 months and name the column as new end date
Query:-
Select add_months(end_date,3) from task_09990302012
4. Give Syntax and Queries to demonstrate the use of following Date functions in System
Defined Table
a. To_Char()
Query:-
Select to_char(12.73,'99.9') from dual
Screenshot:-
Query:-
Select to_char(12.73,'$99.00') from dual
Screenshot:-
Query:-
Select to_char(21,'000099') from dual
Screenshot:-
Query:-
Select to_char(sysdate,'yyy/mm/dd') from dual
Screenshot:-
Query:-
Select to_char(sysdate,'Month DD,YYY') from dual
Screenshot:-
Query:-
Select to_char(sysdate,'MON DDth,YYY') from dual
Screenshot:-
b. To_Date()
Query:-
Select to_date('2003/07/09','yyyy/mm/dd') from dual
Screenshot:-
Query:-
Select to_date('070803','MMDDYY') from dual
Screenshot:-
c. To_number
Query:-
Select to_number('1210.7','9999.9') from dual
Screenshot:-
Query:-
Select to_number('546','999') from dual
Screenshot:-
Assignment 8
Sub Queries
1. What is a sub query?
Ans.A subquery is a query within a query. In Oracle, you can create subqueries within your
SQL statements. These subqueries can reside in the WHERE clause, the FROM clause, or the
SELECT clause.
Ans. ANY :The If any value from outcome of subquery is macthed then desired output will
beretrived.It checks with lowest value.
ALL :It will check for greatest value from outcome of subquery
4. Find the details of those employees whose salary is equal to maximum salary in the
organisation.
Query:-
select * from emp09990302012 where salary=(select max(salary)from emp09990302012)
Screenshot:-
5. Find the details of those employees who earn less than the average salary of the
organisation.
Query:-
select * from emp09990302012 where salary<(select avg(salary)from emp09990302012)
Screenshot:-
7. Find all the details of the employees who draw more than the average salary in the
organisation.
Query:-
select * from emp09990302012 where salary>(select avg(salary)from emp09990302012)
Screenshot:-
8. Find all the details of the person who draws the second highest salary.
Query:-
select * from emp09990302012 where salary=(select max(salary)from emp09990302012
where salary<(select max(salary)from emp09990302012))
Screenshot:-
9. Find the details of all the employees provided atleast 5 persons work in department 4 (use
Exists)
Query:-
select * from emp09990302012 where exists(select * from emp09990302012 where
dept_no=4 group by dept_no having count(*)>5)
Screenshot:-
Query:-
select * from emp09990302012 where exists(select * from emp09990302012 where
dept_no=4 group by dept_no having count(*)>0)
Screenshot:-
10. Find the details of those employees who earn more than the minimum salary of department
no 10.(Use Any)
Query:-
select * from emp09990302012 where salary>any(select salary from emp09990302012
where dept_no = 10)
Screenshot:-
Assignment 9
Views
1. What is view and types of views?
Ans.In SQL, a view is a virtual table based on the result-set of an SQL statement.
A view contains rows and columns, just like a real table. The fields in a view are fields from one
or more real tables in the database.
Types of views:
a. Updateable,
b. Non Updateable
2. Create a table employee with following attributes eno(Primary Key) ,ename ,ecity, salary,
deptno.
Query:-
Query:-
Screenshot:-
Query:-
Screenshot:-
4. In the above view update the ecity to ‘Delhi’ where ename is ‘John’.Update View
Query:-
Screenshot:-
Query:-
Screenshot:-
We cannot insert value from the view into the base table because while inserting the value in the view the
primary key in the base table contains a null Hence, to insert value with help of primary key the view
must contain the primary key column.
Query:-
Screenshot:-
6. Update the above view and increase the salary of all employees of department no. 10 by
Rs.1000.
Query:-
Screenshot:-
Query:-
Screenshot:-
Query:-
Screenshot:-
9. Update the above view and set the max salary to 90000.Observe the result.
Query:-
Screenshot:-
Query:-
Screenshot:-
Query:-
Screenshot:-
INSERT:
While inserting record through a view we need a primary key of the base table for insertion in
the base table
DELETE:
While deleting a record we don’t need a primary key we can simply delete the desired record
UPDATE:
While updating a view if there are grouping functions or having clause , set operator and join
then the view cannot be updated
Assignment 10
Join
1. What are join ? What are different types of joins ?
Ans. SQL joins are used to query data from two or more tables, based on a relationship between certain
columns in these tables.Different SQL JOINs are:
JOIN: Return rows when there is at least one match in both tables.
LEFT JOIN: Return all rows from the left table, even if there are no matches in the right table.
RIGHT JOIN: Return all rows from the right table, even if there are no matches in the left table.
FULL JOIN: Return rows when there is a match in one of the tables.
2. Create the Department table with fields: Dno(Primary Key), Dname, Dloc.Insert the
following values
20 Research Dallas
30 Sales Chicago
40 Operation Boston
50 Payroll Dallas
Query:-
Screenshot:-
3. Create the Employee table with fields: Empno(Primary Key), Ename, Salary, Commission,
Deptno(Foreign Key),Mgrid.Insert the following values.
75 Jones 20000 20
76 Martin 30000 30 75
78 Ford 10000 20
Query:-
Query:-
Screenshot:-
4. Create the SalGrade table with fields: Grade, Lowsal, Highsal.Insert the following values
A 10000 99000
B 20000 29000
C 30000 50000
Query:-
Query:-
Screenshot:-
7. Display Empno.,ename,Grade and salary that should be greater than lowsal and less than
highsal.
Query:-
Select e.empno,e.ename,e.salary,s.grade from empl099 e
inner join salgrade099 s on e.salary>s.lowsal
ande.salary<s.highsal
Screenshot:-
9. Display Empno, Ename, Dname ,Dloc of all the employees using outer join.
Query:-
Select e.empno,e.ename,d.dname,d.dloc from dept099 d
right join empl099 e on d.dno=e.dno
Screenshot:-
10. Display Empno, Ename, Dname ,Dloc of all the departments using outer join.
Query:-
Select e.empno,e.ename,d.dname,d.dloc from dept099 d
left join empl099 e on d.dno=e.dno
Screenshot:-
11. Retrieve employee no, employee name of all the employees along with their manager no and
manager name if any.
Query:-
Select e.ename,e.empno,ev.mgrid
from empl099 e
join empl099 ev on e.empno=ev.mgrid
Screenshot:-
Select e.ename,e.empno,ev.mgrid
from empl099 e
join empl099 ev on e.empno=ev.mgrid
Assignment 99
Revision
1. Create table student with following fields: RollNo(PK), Sname, DOB(not Null), Coursecode(FK), Year of
admission.
Query:-
create table stu099(RollNoint primary key,Snamevarchar(20),DOB date Not Null,ccodeint,constraint rev
foreign key(ccode) references course099,Year_of_admission date)
Query:-
select * from stu099;
Screenshot:-
Screenshot:-
Screenshot:-
select rs.rollno,rs.sname,rs.dob,rs.ccode,rs.year_of_admission,c.cname,c.fee
from stu099 rs
inner join course099 c
onrs.ccode = c.ccode
where cname = 'BBA-CAM'
6. Find the list of students who have taken admission in the 2012.
Query:-
select rs.rollno,rs.sname,rs.dob,rs.ccode,rs.year_of_admission,c.cname,c.fee from stu099 rs
inner join course099 c
onrs.ccode = c.ccode
where year_of_admission = 2012
Screenshot:-
select rs.rollno,rs.sname,rs.dob,rs.ccode,rs.year_of_admission,c.cname,c.fee
from stu099 rs
inner join course099 c
onrs.ccode = c.ccode
where year_of_admission = 2012
7. Find the number of students who have taken admission year wise.
Query:-
select count(*),rs.year_of_admission from stu099 rs
inner join course099 c
onrs.ccode = c.ccode
group by year_of_admission
Screenshot:-
8. Find the details of the students who are in the course in which student with roll no 101 studies.
Query:-
Select * from stu099 where ccode=(select course099.ccode from course099,stu099
where course099.ccode=stu099.ccode
and stu099.rollno=101)
Screenshot:-
Assignment 12
Set Operators
1. What are different set operators?
All the below operators are binary operators that are used to perform different set operation using two
tables.
Union - In this duplicate values are eliminated & we get all the records of both tables.
Union all- In this duplicate records are there & records of both the table are displayed.
Intersection- In this only common record of both the table are diaplayed.
Minus - It returns the difference of two select query i.e the second query is substracted by first query.
2. Create table emp_banglore & emp_delhi with following attributes :eno (primary key),name,salary,dno.
Insert 5 records in emp_banglore and 3 records in emp_delhi.
Query:-
create table emp_bang099(enoint primary key,namevarchar(20),salint,dnoint);
Query:-
select * from emp_bang099;
Screenshot:-
Query:-
create table emp_delhi099(enoint primary key,namevarchar(20),salint,dnoint);
Query:-
select * from emp_delhi099;
Screenshot:-
3. Find out the list of all employees who are working in Delhi & Bangalore.
Query:-
select * from emp_bang099
union
select * from emp_delhi099
Screenshot:-
4. Find out the list of all employees who are working in both the locations.
Query:-
select * from emp_bang099
intersect
select * from emp_delhi099
Screenshot:-
5. Find out the list of all employees who are working only in banglore.
Query:-
select * from emp_bang099
minus
select * from emp_delhi099
Screenshot:-
Assignment13
Index
1. What are Indexes?Why are they required in DBMS
Ans. Index an order list of the contents of column/columns of a table. SQL uses a B-tree structure in
indexes to store and retrieve data. Pointers are used to point these data nodes. Database starts its search
at the top node and follows the pointers. Index is a table access strategy that increases speed of
searching.
Types of index:-
Unique index:-Indexes that do not allow duplicate values for indexed column.
Duplicate index:- Indexes that allow duplicate values for indexed column
Desc emply099
Assignment 14
DCL
1. What is a DCL command explains in detail?
Ans.Data Control Language (DCLDCL Commands are used to enforce database security in a multiple
user database environment. Only Database Administrator's or owner's of the database object can
provide/remove privileges on a database object. Two types of DCL commands are:
GRANT - gives user's access privileges to database
REVOKE - withdraw access privileges given with the GRANT command
SQL GRANT is a command used to provide access or privileges on the database objects to the users.
GRANT privilege_name
ON object_name
TO {user_name |PUBLIC }
privilege_name is the access right or privilege granted to the user. Some of the access rights are
ALL, EXECUTE, and SELECT,update
object_name is the name of an database object like TABLE, VIEW, STORED PROC and
SEQUENCE.
user_name is the name of the user to whom an access right is being granted.
Eg:-create user username identified by password
The REVOKE command removes user access rights or privileges to the database objects.
REVOKE privilege_name
ON object_name
FROM {user_name |PUBLIC |role_name}
2. Create a table student_name with the following fields:-Rollno,name,course,date of birth and subject.
Query:-
create table student_rakesh(rollnoint primary key,namevarchar(20),course varchar(20),dob
date,ccodeint)
Query:-
select * from student_pratik
Screenshot:-
grant select
on
student_pratik
to
bca2
Query:-
grant update
on
student_pratik
to
bca2
Screenshot:-
grant update
on
student_pratik
to
bca2
4. Take away the give priviledge from the user by using the revoke command.
Query:-
revoke select
on
student_pratik
from
bca2
Screenshot:-
revoke select
on
student_pratik
from
bca2
Query:-
revoke update
on
student_pratik
from
bca2
Screenshot:-
revoke update
on
student_pratik
from
bca2
Assignment 15
TCL
1. What are the different TCL command and explain each of them.
Ans. Transaction Control(TCL) statements are used to manage the changes made by DML
statements. It allows statements to be grouped together into logical transactions.
COMMIT
Save point d2
Rollback to d2;
Commit;
2. Use any table that you have created and delete a record from that table. Issue a save point after the
delete operation.
Query:-
select * from empl099
Screenshot:-
Query:-
delete from empl099 where dno=10;
save point d1
Screenshot:-
3. Delete two records from a table where after first record deletion use a savepoint and after the second
record deletion use the rollback to the savepoint.
Query:-
delete from empl099 where dno=20;
save point d2
Screenshot:-