Dbms Final
Dbms Final
ID: 21IT444
PRACTICAL LIST
Sr.
No. Title Date Sign
Study of Oracle Data Types.
1 Creation of Employee Table using DDL command,
Insertion of data into the database tables.
Command to view the data in the table :
all rows and all columns
Filtering Table Data for selected columns and selected
Rows, for all rows and selected columns, for all columns
2 and selected rows
Elimination of duplicated rows when using select statement
Sorting data in a table
Creating a table from table
Insert data into the table from another table.
Commands to perform delete operation:
Removal of all rows, removal of specific row.
Commands to perform update the contents of table.
3 Commands to modify the structure of tables:
Add new column, drop a column, modify existing columns,
restrictions on “alter table” command.
Commands to rename truncate and destroy tables
Data Constraints:
Add primary key, foreign key, unique key, Check
constraint.
4 How these constraints can be add at Column level and table
level.
Define Integrity constraints via Alter table command.
Destroy Integrity constraints via Alter table command.
Oracle functions:
Aggregate functions, Numeric Functions, String Functions,
5
Conversion Functions, Date conversion functions, Date
Functions
pg. 1
DBMS LABMANUAL 21IT444
pg. 2
DBMS LABMANUAL 21IT444
Practical-1
Study of oracle data types:
Data types in SQL defines a sort of value that a database table column can contain. In a
database table, each column is required to have a data type with a name.
CHAR (character)
DEC (Decimal)
NUMERIC
INT (Integer)
SMALLEST
FLOAT
REAL
DOUBLE PRECISION
Oracle-Supplied Types: Oracle offers SQL-based interfaces for defining new types when
the built-in or ANSI-supported types are not satisfactory. The performance and working for
these types can be implemented in C/C++, Java, or PL/ SQL. Oracle Database repeatedly
allows the low-level infrastructure services needed for input-output, varied client-side access
for new data types, and optimizations for data transferring between the application and the
database. The Oracle-supplied types, along with cross-references to the documentation of
their implementation listed as following:
Any Types
XML Types
Spatial Types
Media Types
pg. 3
DBMS LABMANUAL 21IT444
Creating table:
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype,
....
);
Inserting data:
Insertion of data into the database tables.
The SQL INSERT INTO Statement:
The INSERT INTO statement is used to insert new records in a table.
Example:
pg. 4
DBMS LABMANUAL 21IT444
pg. 5
DBMS LABMANUAL 21IT444
Practical-2
Command to view the data in the table:
All rows and all columns-
Filtering Table Data for selected columns and selected Rows, for
all rows and selected columns, for all columns and selected rows-
Syntax:
pg. 6
DBMS LABMANUAL 21IT444
Syntax:
SELECT column1, column2, ...
FROM table_name
WHERE condition;
pg. 7
DBMS LABMANUAL 21IT444
pg. 8
DBMS LABMANUAL 21IT444
pg. 9
DBMS LABMANUAL 21IT444
Practical-3
Commands to perform delete operation:
pg. 10
DBMS LABMANUAL 21IT444
Syntax-
pg. 11
DBMS LABMANUAL 21IT444
Syntax-
DROP TABLE table_name;
Note:- Be careful before deleting a table. Deleting a table, results in loss of all
data stored in the table.
pg. 12
DBMS LABMANUAL 21IT444
Practical-4
Data Constraints:
Add primary key, foreign key, unique key, Check constraint-
pg. 13
DBMS LABMANUAL 21IT444
Note: Unique and primary key are basically same. Both can’t have repeating
values. The difference is that there can be more than one unique key, while
there can be only one primary key.
pg. 14
DBMS LABMANUAL 21IT444
Practical-5
Oracle Functions:
1.Aggregate Function
SQL aggregation function is used to perform the calculations on multiple rows of a single
column of a table. It returns a single value.
It is also used to summarize the data.
1. COUNT FUNCTION
COUNT function is used to Count the number of rows in a database table. It can work on
both numeric and non-numeric data types.
COUNT function uses the COUNT(*) that returns the count of all the rows in a specified
table. COUNT(*) considers duplicate and Null.
Syntax
COUNT(*)
or
COUNT( [ALL|DISTINCT] expression )
pg. 15
DBMS LABMANUAL 21IT444
2. SUM Function
Sum function is used to calculate the sum of all selected columns. It works on numeric fields
only.
Syntax
1. SUM()
2. or
3. SUM( [ALL|DISTINCT] expression )
3. AVG function
The AVG function is used to calculate the average value of the numeric type. AVG function
returns the average of all non-Null values.
Syntax
1. AVG()
2. or
3. AVG( [ALL|DISTINCT] expression )
pg. 16
DBMS LABMANUAL 21IT444
4. MAX Function
MAX function is used to find the maximum value of a certain column. This function determines
the largest value of all selected values of a column.
Syntax
1. MAX()
2. or
3. MAX( [ALL|DISTINCT] expression )
5. MIN Function
MIN function is used to find the minimum value of a certain column. This function determines
the smallest value of all selected values of a column.
Syntax
1. MIN()
2. or
3. MIN( [ALL|DISTINCT] expression )
pg. 17
DBMS LABMANUAL 21IT444
2.String Function
String functions are used to perform an operation on input string and return an output
string.
2.CHAR_LENGTH(): Doesn’t work for SQL Server. Use LEN() for SQL Server. This
function is used to find the length of a word.
3.LOWER(): This function is used to convert the upper case string into lower case.
pg. 18
DBMS LABMANUAL 21IT444
4.LPAD(): This function is used to make the given string of the given size by adding the
given symbol.
5.LTRIM(): This function is used to cut the given sub string from the original string.
6.RPAD(): This function is used to make the given string as long as the given size by
adding the given symbol on the right.
pg. 19
DBMS LABMANUAL 21IT444
7.RTRIM(): This function is used to cut the given sub string from the original string.
8.SUBSTR(): This function is used to find a sub string from the a string from the given
position
9.UPPER(): This function is used to convert the upper case string into upper case.
pg. 20
DBMS LABMANUAL 21IT444
pg. 21
DBMS LABMANUAL 21IT444
Practical-6
Study of group by and having clauses
Group by
The GROUP BY statement groups rows that have the same values into summary rows, like
"find the number of customers in each country".
GROUP BY Syntax
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s);
EX:
HAVING Clause
The HAVING clause was added to SQL because the WHERE keyword cannot be used with
aggregate functions.
HAVING Syntax
SELECT column_name(s)
FROM table_name
WHERE condition
pg. 22
DBMS LABMANUAL 21IT444
GROUP BY column_name(s)
HAVING condition
ROLL UP GROUP BY
The ROLLUP is an extension of the GROUP BY clause. The ROLLUP option allows you to
include extra rows that represent the subtotals, which are commonly referred to as super-
aggregate rows, along with the grand total row. By using the ROLLUP option, you can use a
single query to generate multiple grouping sets.
SYNTAX:
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY ROLLUP(C1,C2);
ROLL UP CUBE BY
The CUBE operator generates multiple grouping sets inside a GROUP BY.
CUBE generates subtotals across all column combinations specified in GROUP BY.
SYNTAX:
SELECT column_name(s)
FROM table_name
pg. 23
DBMS LABMANUAL 21IT444
WHERE condition
GROUP BY CUBE(C1,C2);
SUB QUERIES
A subquery is a SQL query nested inside a larger query.
A subquery may occur in :
- A SELECT clause
- A FROM clause
- A WHERE clause
The subquery can be nested inside a SELECT, INSERT, UPDATE, or DELETE
statement or inside another subquery.
A subquery is usually added within the WHERE Clause of another SQL SELECT
statement.
You can use the comparison operators, such as >, <, or =. The comparison operator
can also be a multiple-row operator, such as IN, ANY, or ALL.
A subquery is also called an inner query or inner select, while the statement
containing a subquery is also called an outer query or outer select.
The inner query executes first before its parent query so that the results of an inner
query can be passed to the outer query.
Syntax :
pg. 24
DBMS LABMANUAL 21IT444
pg. 25