0% found this document useful (0 votes)
47 views

SCAX1001 Course Name: Computer Applications in Business Chapter Name: Rdbms Subject Coordinator: Mrs - Jancy

This document provides information about the course "Computer Applications in Business" including the chapter on Relational Database Management Systems (RDBMS). It defines key terms related to RDBMS like table, row, column, record, cell. It also describes the basic components of a database system including the database management system and database application. Finally, it explains common data types in RDBMS and SQL commands like DDL, DML, TCL along with examples.

Uploaded by

Gracy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

SCAX1001 Course Name: Computer Applications in Business Chapter Name: Rdbms Subject Coordinator: Mrs - Jancy

This document provides information about the course "Computer Applications in Business" including the chapter on Relational Database Management Systems (RDBMS). It defines key terms related to RDBMS like table, row, column, record, cell. It also describes the basic components of a database system including the database management system and database application. Finally, it explains common data types in RDBMS and SQL commands like DDL, DML, TCL along with examples.

Uploaded by

Gracy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

COURSE CODE: SCAX1001

COURSE NAME: COMPUTER APPLICATIONS IN BUSINESS


CHAPTER NAME: RDBMS
SUBJECT COORDINATOR: MRS.JANCY

Unit –V
Relational Database Management System (RDBMS)
 One of the most popular types of database. It was developed by Dr. EF CODD at IBM in the late
1960s.
 In our system keeping computerized records, user can store view, change, and retrieve data in a
standardized way. One of the standardized way is RDBMS.
 RDBMS is based on “table” which is also called “relations”.
 These tables are made up of rows and columns.
 Each table in the database contains only a subset of information.
 A different table contains different information.
Terminology (Important Terms)
Data: Raw facts. Collection of information.
Database: Collection of related data stored in standard format, designed to be processed, shared by
different users.
Table: Collection of data arranged in rows and columns.
Row: In datatable, data laid out in rows are horizontal. go from left to right.
Column: In datatable, data laid out in rows are vertical. go from top to bottom.
Attibutes (Fields): Smallest units of information user can access are placed in a column.
Record: Complete set of information. Records are placed in a row.
Cell: In database table, each cell is identified by a combination of “row” and column coordinates to
which it belongs.
Frontend (Client side): Interact with the database by requesting and receiving information from the
database server.
Backend (Server side):
 Interface between the server and database.
 It is used to manage the database among multiple clients.
Database System
Two parts
1. Database management System

1
DBMS is the program that organizes and maintains information.
2. Database Application
DBA is the program that lets us view, retrieve and update information stored in DBMS.

Data Types
RDBMS supports various data types
NUMBER: The syntax for NUMBER is NUMBER (P, S) p is the precision and s is the scale. P can range from 1
to 38 and s from -84 to 127
Character: CHAR (len) is fixed length character strings
Fixed length character data of length len bytes. This should be used for fixed length data.
Varchar2 (len) Variable length character strings Variable length character string having maximum length len
bytes. We must specify the size.
Date –Dates 12-mar-03.
Numeric: 21, -32, $0.75, 1.2E4.
String: enclosed within ‘…’
Operators
1. Arithmetic Operators (+, -, *, /).
- Used to do Arithmetic operation for addition, subtraction, multiplication and division.
2. Logical Operators (AND, OR, NOT).
- Used to combine one or more conditions.
3. Relational Operators (=, <=, >=, <>).
- used to compare the values.
DDL Commands
 Data Definition Language (DDL).
 Used to define the database structure or schema.
Commands are
1. CREATE
 This command is used to create a table in the database.
Syntax:
create table tablename(Fieldname1 datatype (width),…………… Fieldnamen datatype
(width));
Eg:
create table student(stuname varchar(30),sturno number(10));
Table created.

2
2. ALTER
This command is used to add and modify the existing column definition.
 Add – Used to add a new column in existing table.
 Modify – Used to modify the datatype and width in existing table.
Syntax:
alter table tablename add(new fieldname datatype(width));
Eg:
alter table student add(sturegno number(10) );
Table Altered.
Syntax:
alter table tablename modify (oldfieldname newdatatype (width));
Eg:
alter table student modify(sturegno number(20) );
Table Altered.
3. DROP
 Delete table from the database.
Syntax: drop table tablename;
Eg:
drop table student;
Table Dropped.
4. TRUNCATE
Remove all records from a table including all spaces.
5. COMMENT
Add comment to the data dictionary.
6. RENAME
Rename an Object (Rename the Table).
DML Commands

 Data Manipulation Language.


 Managing Data within Schema Objects.
Commands are
1. SELECT
 Retrieve data from the Database.
Syntax:
a) Selecting the full records

3
Syntax: Select * from tablename;
b) Selecting specific column
Syntax: Select * from tablename where condition;
Eg:
Select * from student;
Select * from student where sturno=101;
2. INSERT
 Insert command is used to add one or more rows to a table.
 The values must be entered in the same order as they are defined in the table.

Syntax:
a) Inserting only one record into table
Syntax:
insert into tablename values (value1, value2,…,value n);
b) Inserting more than one record into table
Syntax:
insert into tablename values (&Fieldname1, &Fieldname2,…….&Fieldname);
Eg:
insert into student values(‘joy’,101,301);
insert into student values(&stuname ,&sturno,&sturegno);
3. UPDATE
 Updates existing data with in a table.
 Update command is used to alter the column values in a table, it consist of ‘set’
clause, used to set each field with some values and also includes optional ‘where’
clause.
Syntax:
update tablename set fieldname=value where condition;
Eg:
update student set sturegno=104 where sturno=101;
4. DELETE
 Delete all records from a table, the space for the records remains.
 To delete specific rows ‘where’ condition is used.
a) Delete all records
Syntax:

4
Delete from tablename;
b) Deleting selected records
Syntax:
delete from tablename where condition;
Eg:
delete from student;
delete from student where sturegno=301;
TCL Commands
 Transaction control language.
 Used to manage the changes made by DML statements.
 It allows statements to be grouped together into logical transactions.
Commands are
1. Commit
 We want to save transaction we can use this command.
 Used to save work done.
Syntax:
commit;
2. Rollback
 Restore database to original since the last commit.
 Its similar to undo commands.
Syntax:
rollback;
3. Save point
 It is a way of implementing sub transaction with in a RDBMS.
 Save point identify a point in a transaction to which you can later “roll back to” without
affecting any work done in the transaction before the savepoint was created.
 Useful for implementing complex error recovery in database applications
Syntax:
savepoint name;
rollback to name;
Eg: Using DDL, DML and TCL Commands
Create a table employee
Query:

5
create table employee (eno number (4), ename varchar2(25), salary number(10,2), designation
varchar2(20),DOJ date);
Table Created
Modify the width value in eno
Query:
alter table employee modify(eno number(8));
- It has modified by width from number (4) to number (8).
Insert a 3 record into employee table
Query:
insert into employee values (1001, ‘Ram’,10000,’programmer’,’10-jun-07’);
insert into employee values (1002, ‘Sam’,20000,’programmer’,’14-jul-08’);
insert into employee values (1003, ‘Jim’,30000,’projectMgr’,’10-jan-06’);

Add a new column name bonus into employee


Query:
alter table employee add(bonus number(10, 2));
Set the bonus value into employee using update command
Query:
update employee set bonus=salary*0.05 where eno=1001;
Select the information from the table
select * from employee;
eno ename salary designation DOJ
1001 Ram 10000 programmer 10-jun-07
1002 Sam 20000 programmer 14-jul-08
1003 Jim 30000 projectMgr 10-jan-06
Save transaction
Query:
commit;
Create the savepoint
savepoint tb;
after create the savepoint user can do n no. of transaction its not affect the original table. Now the original table
is safe mode.
Delete the table
delete from employee where eno=1001;

6
Display the employee information
select * from employee;
eno ename salary designation DOJ
1002 Sam 20000 programmer 14-jul-08
1003 Jim 30000 projectMgr 10-jan-06
Rollback Operation
rollback to ta;
After rollback to table employee now user will get original table
Display the employee information
select * from employee;
eno ename salary designation DOJ
1001 Ram 10000 programmer 10-jun-07
1002 Sam 20000 programmer 14-jul-08
1003 Jim 30000 projectMgr 10-jan-06
WHERE, ALL, DISTINCT, BETWEEN, IN, LIKE, ORDERBY

 Retrieve the records using these types of operators in select commands.


1. WHERE – If u want to Selecting specific records using this command.
Syntax:
select * from tablename where condition;
2. ALL – Return all values in specified column.
Syntax:
select All(columnname) from tablename;
3. DISTINCT - Return distinct values (without duplicate values) in specified column .
Syntax:
select Distinct(columnname) from tablename;
4. BETWEEN – Used to search the ranging between two values.
Syntax:
select * from tablename where columnname Between value1 And value2;
5. IN – Used to specify the multiple values in where clause.
Syntax:
select * from tablename where columnname In(value1, value2,…);
6. LIKE – Used to search for specified pattern in a column.
Syntax:

7
select * from tablename where columnname Like ‘a%’;
- % sign can be used to define wildcard (missing letter in the pattern) both before and after the
pattern.
‘a%’ – start with alphabet ’a’
‘%a’ – ends with alphabet ’a’
‘%a%’ – any where (middle).

7. ORDERBY – Selecting record in sorted order.


Syntax:
select * from tablename Orderby columnname;
Eg: Using Between, Like, Orderby, In, Where, All, Distinct
College Table
rno sname DOB dept per
101 AAA 10-09-89 MBA 88
102 ABC 11-10-88 MCA 85
103 BBB 11-07-86 MSC 92
104 ABC 02-06-87 MBA 95

1. Select name percentage of all students with percentage between 85 & 90.
Query:
Select sname, per from college where per Between 85 And 90;
Output:
sname per
AAA 88
ABC 85
2. Select name, department of all students whose department in MBA and MCA.
Query:
Select sname, dept from college where Dept In(‘MBA’,’MCA’) ;

Output:

sname dept
AAA MBA

8
ABC MCA
ABC MBA

3. Select all records where name is start with alphabet ‘A’.


Query:
Select * from college where sname Like ‘A%’;
Output:

Rno sname DOB dept per

101 AAA 10-09-89 MBA 88

102 ABC 11-10-88 MCA 85

104 ABC 02-06-87 MBA 95

4. Select rollno and name of all records sorted in Orderby percentage.


Query:
Select rno, sname from college Orderby per desc;
Output:
Rno sname DOB dept per
104 ABC 02-06-87 MBA 95
103 BBB 11-07-86 MSC 92
101 AAA 10-09-89 MBA 88
102 ABC 11-10-88 MCA 85
5. Select only first record.
Query:
Select * from college where sname =’AAA’;
Output:

rno sname DOB dept per


101 AAA 10-09-89 MBA 88

6. Select all students name using All operator.


Query:

9
Select All (sname) from college;
Output:

sname
AAA
ABC
BBB
ABC

7. Select all students name using Distinct operator.


Query:
Select Distinct (sname) from college;
Output:
sname

AAA

ABC

BBB

Aggregate Functions
SQL - Aggregate functions
 Aggregate functions work on all the rows of the table taken as a group (based on some condition
optionally).
 Used when information you want to extract from a table has to do with the data in the entire table
taken as a set.
 Aggregate functions are used in place of column names in the SELECT Statement.
 The aggregate functions are :
SUM ( ), AVG ( ), MAX ( ), MIN ( ), COUNT ( )
Aggregate function - SUM
 Adds up the values in the specified column.
 Column must be numeric data type.
 Value of the sum must be within the range of that data type.
Syntax:
select sum(columnname)from tablename where condition;
Aggregate function – AVG

10
 Returns the average of all the values in the specified column.
 Column must be numeric data type.
Syntax:
select avg(columnname)from tablename where condition;
Aggregate function - MAX
 Returns the largest value that occurs in the specified column.
Syntax:
select max (columnname)from tablename where condition;
Aggregate function - MIN
 Returns the smallest value that occurs in the specified column.
Syntax:
select min(columnname)from tablename where condition;
Aggregate function – COUNT
 Returns the number of rows in the table.
Syntax:
select count(columnname)from tablename;
(or)
count(*) returns Number of rows
Using two or more aggregate functions:
Syntax:
select min(columnname), max(columnname) from tablename where condition;
Example:
Library Table
Bname Bcode Price
Clm 101 250
Java 102 300
Dbms 103 200
Oracle 104 500

1. select sum(Price)from Library;


Output:
1250
2. select avg(Price)from Library;
Output:

11
312.5
3. select max(Price)from Library;
Output:
500
4. select min(Price)from Library;
Output:
200
5. select count(*)from Library;
Output:
4
Set Operators

Retrieval of records using UNION / UNION ALL

Union – It return only distinct values (without duplicate values).


UnionAll – It returns all values including duplicate values

Syntax:
select columnname from tablename1 union select columnname from tablename2;
select columnname from tablename1 unionall select columnname from tablename2;

The results of two independent SELECT statements can be worked with using the SET operation
UNION/ UNIONALL. By default, UNION returns only distinct values. Union is like an “OR” operation. If the tuple
occurs in relation 1 or relation 2, it is selected.

Retrieval of records using INTERSECT

12
An intersection is an AND operation. It retrieves those tuples which are present in both relation A
and B
Syntax:
select columnname from tablename1 intersect select columnname from tablename2;
Retrieval of records using Minus

This is the difference operation. It retrieves tuples which are present in relation 1 but not in relation 2.
Syntax:
select columnname from tablename1 Minus select columnname from tablename2;
Example:
Customercity

Name Id City
AAA 101 Chennai
BBB 102 Mumbai
CCC 103 Bangalore

Suppliercity

Name Id City
XXX 101 Chennai
YYY 102 Delhi
ZZZ 103 Chennai

1. select City from Customercity union select City from Suppliercity;

13
Output:
City
Chennai
Mumbai
Bangalore
Delhi
2. select City from Customercity unionall select City from Suppliercity;
Output:
City
Chennai
Mumbai
Bangalore
Chennai
Delhi
Chennai

3. select City from Customercity intersect select columnname from Suppliercity;


Output:
City
Chennai

4. select City from Customercity Minus select city from Suppliercity;


Output:
City
Mumbai
Bangalore

ASSIGNMENT QUESTIONS

14
A. DDL OPERATION TO BE PERFORMED

1. In a single SQL statement, create a table called QUESTION. It should have four columns:
--Email. Datatype: varchar2. Width: 35. Cannot be null.
--RecDate. Datatype: date. Cannot be null.
--Name. Datatype: varchar2. Width: 50. Can be null.
--Question. Datatype: varchar2. Width: 500. Cannot be null.
2. Now use an ALTER statement to add an alternate Email address with varchar data type.
3. View the resulting table schema with "desc".
4. Alter statement to modify the Data types for Name field.
5. View the table schema again to show the results of your changes.
B. DML OPERATIONS TO BE PERFORMED:
1. To create employee table with ename, eid, doj, basicpay, age, address fields.
2. Insert five records to the employee database.
3. Increment the basic pay of all the employees by 5% of their basic pay.
4. Delete the third employee record from the table.
C. DQL OPERATIONS TO BE PERFORMED:
Create a student detail database with roll number, name, date of birth, course, department, semester,
percentage. Insert 5 records into the database and perform the following operations.
1. Select all Records.
2. Select name, percentage from the records.
3. Select distinct course.
4. Select details of all students with percentage greater than 75.
5. Select roll number and name of all records sorted in order by percentage.
6. Select name of students belonging to 3rd semester MBA degree.

D. TCL OPERATIONS TO BE PERFORMED:

1. To create student table with rno, sname, dob,course,sem,percentage fields.


2. In the student database make the transaction as permanent using Commit command.
3. Undo the transaction performed in the database using Rollback.
4. Select a point and implement Savepoint command which is later rollbacked to.
E. SQL OPERATIONS TO BE PERFORMED:

15
Create a library database with book name, author name, access code, date of access, publisher name,
and price as the fields.
i. Select the average price of all books in the library database.
ii. Select the name of the book with maximum price in the given database.
iii. Select the book with minimum price.
iv. Count the number of records in the library database.
v. Print the total (total cost of all the books) estimate of the library book.

REFERENCE LINK
www.tutorialspoint.com/sql/sql-rdbms-concept.html
www.studytonight.com/dbms/rdbms-concept

16

You might also like