Dbms Practical File PDF
Dbms Practical File PDF
Dbms Practical File PDF
PRACTICAL FILE
SUBJECT: DBMS-LAB(CSE-212-F)
Theory: The ‘sequel’ is the abbreviation for structured query language. The SQL
consists of a set of facilities for defining, accessing and managing relational databases.
All tasks related to relational data management- creating tables, querying the database,
deleting, granting access to users etc., can be done using SQL. Is has been accepted as
an American standard by American National Standards Institute (ANSI) and is a
Federal Information Processing Standard (FIPS). The first commercial DBMS that
supported SQL was Oracle in 1979. SQL statements can be invoked either
interactively in a terminal session or by embedding them in application programs.
The SQL language is mainly divided into four major parts. These four parts are further
divided into subparts. The major parts are as follows:
----------------------------------------------);
( rollno int,
name char(15),
place char(20),
deptid int);
( id int,
deptname char(15),
loc char(20));
Insert statement
VALUES(‘13521’, 'Ravi','Rohtak','1');
VALUES(‘13519’, 'Sachin','Bhiwani','1');
VALUES( 'Vijay','Sonipat','2');
VALUES(‘13443’,’Rajat’,'3');
VALUES(‘13511’, 'Viren','Rohtak','2');
VALUES(‘13493’, 'Dev','Bahadurgarh');
VALUES(‘13469’, 'Parshant','Rohtak','4');
The above statements will insert the respective values in the table ‘data’. The table
will look like this
Example: INSERT INTO debt
VALUES(‘1’,’CSE’,’ComputerBlock’);
VALUES(‘2’,’Civil’,’CivilBlock’);
VALUES(‘3’,’ECE’,’ComputerBlock’);
VALUES(‘4’,’Biotech’,’BioBlock’);
The above statements will insert the respective values in the table ‘debt’. The table
will look like this
PRACTICAL: 3
Theory: Alter table statement is used to add or drop columns of tables and to
modify name and attributes of an existing column.
• To drop a column:
MODIFY(name char(30));
WHERE <condition>;
WHERE name=’parshant’;
Update Statement is used to modify the values of existing rows.
Where <condition>;
Note: All rows in the table satisfy the conditions are updated.
SET name=’devender’
WHERE rollno=’13493’;
PRACTICAL: 5
Aim: To study the various query processing statements.
FROM <table-name>;
Example: To display all names and rollno of the students, the query is
SELECT rollno,name
FROM data;
FROM <table-name>;
FROM data;
Where Clause: Where clause is used to select particular rows from table.
FROM <table-name>
WHERE <condition>;
SELECT name
FROM data
WHERE deptid=1;
Operators: The various operators provided by SQL are as follow:
Operator Description
= Equal to
> Greater than
< Less than
>= Greater than equal to
=< Less than equal to
<> Not equal to
IN Checking the value within a set
BETWEEN Checking the vale within a range
LIKE Matching the pattern of characters
IS NULL Checking the null value
AND It returns true if both conditions are
true
OR It returns true if either condition is
true
NOT It returns true if condition is false
• List all names and place of students having roll no. greater than 13501
SELECT name,place
FROM data
WHERE rollno>13501;
Theory: Character functions are the sub type of Single Row Functions. The various
character functions provide by SQL are as follow:
Function Description
LENGTH(‘string’) It returns the number of characters in
string
LOWER(‘string’) It converts string to lowercase
UPPER(‘string’) It converts string to uppercase
INITCAP(‘string’) It converts only first character of each
word in string to uppercase
CHR(x) It returns equivalent character value of
integer x
CONCAT(‘string 1’,string 2’) It joins both the strings. It is equivalent to
concatenation operator
REPLACE(‘string’,’search It replaces every occurrence of search str
str’,’replace str’) with replace str within string
SUBSTR(‘string’,m,[n]) It returns a substring starting from mth
position and up to nth position
INSTR(‘string’,’char’) It returns position of first occurrence of
char in string
Dual Table: Dual table is used to explain single row functions. It has one column
name Dummy and one row having value x.
• SELECT LENGTH(‘Ravi’)”Output”
FROM dual;
• SELECT LOWER(‘Virender’)”Output”
FROM dual;
• SELECT UPPER(‘Sachin’)”Output”
FROM dual;
• SELECT INITCAP(‘ravibazad’)”Output”
FROM dual;
• SELECT CHR(103)”Output”
FROM dual;
• SELECT CONCAT(‘Ra’,’vi’)”Output”
FROM dual;
• SELECT SUBSTR(‘database’,3,7)”Output”
FROM dual;
• SELECT INSTR(‘database’,’b’)”Output”
FROM dual;
PRACTICAL: 7
Theory: Number functions are also known as arithmetic functions. They accept
numeric data and returns numeric values. The various numeric functions are :
Function Description
CEIL(x) It returns the smallest integer greater than
or equal to x.
FLOOR(x) It returns the largest integer less than or
equal to x.
ABS(x) It returns the absolute value of x.
POWER(x,y) It returns x raised to the power y.
MOD(x,y) It returns the remainder of x divided by y.
SIGN(x) It returns +1 if x is positive or -1 if x is
negative.
ROUND(x,y) It rounds the column. Y specify the
number of digits after decimal. If y is
omitted then there are no decimal places.
If y is negative, numbers to the left of
decimal point are rounded.
EXP(x) It returns e raised to the power x.
SQRT(x) It returns square root of x. If x is negative
NULL is returned.
TRUNC(x,y) It truncates the column. Y specify the
number of digits after decimal. If y is
omitted then there are no decimal places.
If y is negative, numbers to the left of
decimal point are truncated.
• SELECT CEIL(14.8)”Output”
FROM dual;
• SELECT FLOOR(14.6)”Output”
FROM dual;
• SELECT ABS(-15)”Output”
FROM dual;
• SELECT POWER(7,2)”Output”
FROM dual;
• SELECT MOD(5,2)”Output”
FROM dual;
• SELECT ROUND(77.123)”Output”
FROM dual;
• SELECT EXP(4)”Output”
FROM dual;
• SELECT SQRT(49)”Output”
FROM dual;
• SELECT TRUNC(79.128,2)”Output”
FROM dual;
PRACTICAL: 8
Theory: Group functions are those functions that operate on a group of rows and
return a single result per group. Group may be entire table or a part of table. All the
group functions ignore null values. The various group functions are:
Function Description
MAX(column name) It returns the maximum value of a given
attribute, ignoring NULL values.
MIN(column name) It returns the minimum value of a given
attribute, ignoring NULL values.
AVG(column name) It returns the average value of column
values, ignoring NULL values.
SUM(column name) It returns the sum of column values,
ignoring NULL values.
COUNT(* column name) It returns the total number of rows.
• SELECT MAX(rollno)”Output”
FROM data;
• SELECT MIN(name)”Output”
FROM data;
• SELECT AVG(deptid)”Output”
FROM data;
• SELECT SUM(deptid)”Output”
FROM data;
Theory: Join Operation: If we need information from more than one table then we
use joins. To join tables the condition need to be specified. The different join
operations available are:
• Equijoin: When two or more tables are joined by equality of values in one or
more columns then it is called Equijoin.
Note: More than two tables can be joined by using logical operators.
• Non-Equijoin: When tables are joined by any other operator except the quality
operator in condition, then it is known as Non-Equijoin.
• Left Outer join: To display all the rows of table left of the join condition, use
LEFT OUTER JOIN. This keyword is used instead of outer join operator ‘(+)’.
• Right Outer Join: To display all the rows of table right of the join condition,
use RIGHT OUTER JOIN. This keyword is used instead of outer join operator
‘(+)’.
FROM data,debt;
Union operator: The UNION operator is used to combine the result-set of two or
more SELECT statements.
Note: Each SELECT statement within the UNION must have the same number of
columns. The columns must also have similar data types. Also, the columns in each
SELECT statement must be in the same order.