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

Unit 3 RDBMS

The document discusses the concepts of databases and database management systems. It covers topics like the different components of a database, data types, keys, relationships between tables, and how to create and manage tables.

Uploaded by

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

Unit 3 RDBMS

The document discusses the concepts of databases and database management systems. It covers topics like the different components of a database, data types, keys, relationships between tables, and how to create and manage tables.

Uploaded by

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

CONTENTS

SESSION1:Appreciate the Concept of Database Management


System

SESSION2: Create and Edit Tables using Wizard and SQL


Commands

SESSION3:Perform Operations on Table

SESSION4:Retrieve Data Using Query

SESSION5:Create Forms and Reports Using Wizard

1|Contents
UNIT–3
RDBMS
SESSION:1 APPRECIATE THE CONCEPT OF DATABASE MANAGEMENT SYSTEM
Database–A database is an organized collection of data. You can visualize it as a
container of information. The data is typically organized to model relevant aspects
of reality (for example, the availability of rooms in hotels), in a way that supports
processes requiring this information (for example, finding a hotel with facilities
such as Laundry, GYM etc…).

Database Management System(DBMS)-

A database management system is a software package with computer programs


that controls the creation, maintenance and use of a database. A DBMS allows
different user application programs to concurrently access the same database.
Some of the DBMSs are Oracle, IBMDB2, Microsoft SQL server, Microsoft Access,
PostgreSQL, MySQL, FoxPro and SQLite.

Data can be organized in to two types:-


Flat File: Data is stored in a single table. Usually suitable for less amount of data.
Relational : Data Is stored in multiple tables and the tables are linked using a
common field. Relational is suitable for medium to large amount of data.
Advantages of Database
•Data entry, Update, read and delete cost is reduced.
•Reduced data redundancy.
•Data sharing is made easy.
•Data inconsistency is reduced.
•The end-user's productivity is improved.

2|Contents
•Decision making with data is improved.
•Improved data access.
•Better data integration.
Features of DBMS • Query Ability.
•Backup & Replication
•Security
•Computation
•Automated optimization
Database Servers–Database servers are dedicated computers that hold the actual
databases and run only the DBMS and related software. Databases on the database
servers are accessed through command line or graphic user interface tools referred
to as Front ends; database servers are referred to as Back-ends. Such type of data
access is referred to as Client-server model.

RDBMS:- It was introduced by E.F.Codd, of IBM’s San Jose Research Laboratory.


Based on first-order predicate logic,first formulated and proposed in 1969 by Edgar
F.Codd. A relational database management system(RDBMS) is a database
management system that is based on the relational model. In the relational model
of a database, all data is represented in terms of tuples(rows), grouped in to
relations(tables). A database organized in terms the relational model is a relational
database. Database Concepts:- Database contains objects that are used for storing
and managing information.
1.Item:- Item is about which information is stored in the database.
2.Field:- Fields are the components that provide structure for a table. You can't
have a table without fields. For instance, you can create an empty table that has
fields defined but no rows (records). In databases, fields are used to maintain
relationships between tables.
3.Record:- Record is a set of information(made up of fields) stored in your database
about one of the items.

3|Contents
4.Value:- Value is the actual text or numerical amount or date that you put in while
adding information to your database.

For example,
Database:-Employee
Emp_Co Emp_Na Emp_A Emp_Designat Emp_Cont Emp_Sal
de me dd ion act ary
E001 ABC Meerut Manager 987654321 Rs.50,000

5.KeyField:- Key Field is a value in a Field that uniquely identifies the record.
Eg.E001 which is unique to every employee.
Important Question:- How data is organized in a RDBMS?
Ans:- In RDBMS, data is organized in the form of interlinked tables.
KEYS:- A DBMS key is an attribute or set of an attribute which helps you to identify a
row(tuple) in a relation(table).
PRIMARY KEY:- A primary key is a unique value that identifies a row in a table.
These keys are also indexed in the database, making it faster for the database to
search a record. The Primary Key can't be a duplicate value.
A table can not have more than one primary key.
PROPERTIES OF PRIMARY KEY:-
•There can only be one primary key for a table.
•The primary key consists of one or more columns.
•The primary key enforces the entity integrity of the table.
•All columns defined must be defined as NOT NULL.
•The primary key uniquely identifies a row.
COMPOSITE PRIMARY KEY:- Composite key, or composite primary key, refers to
cases where more than one column is used to specify the primary key of a table.

4|Contents
It may be a candidate key or primary key.
ALTERNATE KEY:- It is a column or group of columns in a table that uniquely
identify every row in that table. A table can have multiple choices for a primary
key but only one can be set as the primary key. All the keys which are not
primary key are called an Alternate Key.
CANDIDATE KEY is a set of attributes that uniquely identify tuples in a table.
Candidate Key is a super key with no repeated attributes. The Primary key should
be selected from the candidate keys. Every table must have at least a single
candidate key. A table can have multiple candidate keys but only a single primary
key.
PROPERTIES OF CANDIDATE KEY:• It must contain unique values
•Candidate key may have multiple attributes
•Must not contain null values
•It should contain minimum fields to ensure uniqueness
•Uniquely identify each record in a table

FOREIGN KEY:- The foreign key identifies a column or set of columns in one
(referencing) table that refers to a column or set of columns in another (referenced)
table. Or FOREIGN KEY is a column that creates a relationship between two tables.
The purpose of Foreign keys is to maintain data integrity and allow navigation

5|Contents
between two different instances of an entity. It acts as across-reference between
two tables as it references the primary key of another table.

This concept is also known as Referential Integrity.


Note:- The “one” side of a relation is always the parent, and provides the
PK(Primary Key) Attributes to be copied. The “many” side of a relation is always the
child, in to which the FK(Foreign Key) attributes are copied.

Memorize it: one, parent, PK(Primary Key); many, child, FK(Foreign Key)

SESSION2:-CREATE AND EDIT TABLES USING WIZARD AND SQL COMMANDS

TABLE:- A table is a set of data elements that is organized using a model of vertical
columns and horizontal rows. Each row is identified by a unique key index or the
key field.

COLUMNS OR FIELD:- A column is a set of data values of a particular simple type,


one for each row of the table. For eg. Emp_Code, Emp_Name , Emp_Address etc.
ROWS OR RECORDS OR TUPLES:- A row also called a Record or Tuple represents a
single, data items in a table. Each row in a table represents a set of related data,
and every row in the table has the same structure.

6|Contents
DATA TYPES:- Data types are used to identify the type of data we are going to store
in the database.
Categories of data types:- Data types in Open Office Base are broadly
classified in to five categories:
1.Numeric Types
2.Alphanumeric Types
3.Binary Types
4.Date Time
5.Other variable Types

NUMERIC TYPES:- They are used for describing numeric values like mobile number,
age, etc.
The different types of numeric data types available are-
1.Boolean(Yes/No) 6.Numeric
2.TinyInt(Tiny Integer) 7.Decimal
3.SmallInt(Small Integer) 8.Real
4.Integer 9.Float
5.BigInt(Big Integer) 10.Double
ALPHANUMERICTYPES:-
The list of different data types available in alphanumeric types are:
1.Long VarChar(Memo)(Long Text)
2.Char (Text-fix)(Small Text)
3.VarChar (Text) (Text of specified Length)
4.VarChar_IgnoreCase(Text)(Comparisons are not case sensitive)

7|Contents
BINARY TYPES:-
Binary types are used for storing data in binary formats. It can be used for storing
photos, music files or (in general file of any format)etc.
The list of different data types available in Binary types are:
1.LongVarBinary (Image)
2.Binary (Binary(fix))

3.VarBinary (Binary)

DATETIME:-
Datetime data types are used for describing date and time values for the field used
in the table of a database. It can be used for storing information such as date of
birth, date of admission etc.
The list of different data types available in DateTime type are:
1.Date(Stores month, day and year information)
2.Time(Store hour, minute and second information)
3.Timestamp(Stores date and time information)
OTHERDATATYPES:-
Other/Object-Store serialized Java objects.
LAUNCHING OPEN OFFICE BASE
Click Start>Programs>OpenOffice.org3.4.1>OpenOffice.orgBase.
A dialog box will appear. To create new Database, select option Create A New
Database.
To open an existing database, select the option Open an existing database file.
Then click Next, then Finish.

8|Contents
Save As dialog box will appear. Specify a name for the database in the File name:
field and click Save. Now that you have created a database, you can work with the
database as outlined in the next few sessions.
To Create Table in Design View:-
Click on Create Table in Design View… option available under Tasks and a Table
Design window appears as shown below.

Specify the field name and data type of the field to be created by selecting the
appropriate type available under Field type drop down list.
After specify the field name and data type for the field variable, save the table by
clicking on FILE>SAVE. Save as dialog box will appear. Specify the table name. The
default name is Table1. Click OK.
A dialog box appears, similar to the one displayed below.

If you click Yes, the application will set the primary key for the first field created
automatically. If you click No, you should see a window similar to the one displayed
below.

9|Contents
Figure11

Notice the table by the nameS Details created and visible under Tables section.
Start typing the records in the table and select File>Save current record to save data
in the table.
Create table using SQL DDL Command Example:
To create a student table, SQL command used is as follows:
Create table Student
(Stud_Id int Primary Key, Stud_Name varchar(20),Stud_Class varchar(3),
Stud_Address varchar(30));

10|Contents
SESSION3
PERFORM OPERATIONS ON TABLE

In a database we can define the structure of the data and manipulate the data
using some commands. There are two types of languages:-
1.DDL (Data Definition Language)
2.DML(Data Manipulation Language)

DATA DEFINITION/DESCRIPTION LANGUAGE:-It is a standard for commands that


define the different structures in a database. DDL statements create, modify and
remove database objects such as tables, indexes and users.

Common DDL Statements are:-


1. Create:-Used to create database objects.
Syntax: CREATETABLE ‘’table_name’’(‘’column1’’ datatype, ‘’column2’’ datatype,
‘’column3’’ datatype,…..)
2.Alter:-Used to modify database objects.
Syntax: ALTER TABLE ‘’table_name’’ ADD ‘‘columnname’’ datatype;.
3.Drop:- Used to delete database objects.
Syntax:
DROP DATABASE name– complete information present in a database will be lost.
DROP TABLE TableName– complete information present in a table will be lost.
TRUNCATE Table TableName– Your information will be lost, but not the
table.

DATA MANIPULATION LANGUAGE:-It is a standard for commands that enables users


to access and manipulate data in a database.

11|Contents
Common DML Statements are:-
1.SELECT:-Used for retrieval of information from the database.
2.INSERT:- Used for insertion of new information in to the database.
3.DELETE:- Used for deletion of information in the database.
4.UPDATE:- Used for modification of information in the database.

Types of DML:-
1.Procedural:- The user specifies what data is needed and how to get it.
2.NonProcedural:- The user only specifies what data is needed.
Note:-A popular data manipulation language is SQL(Structured Query Language.)
SQL commands are also used to manage and manipulate data in a database. A
query language is a part of DML involving information retrieval only. The terms
DML and query language are often used synonymously.
INSERT statement: It is used to add one or more records to a database.
Syntax: INSERT INTO ’’table_name’’ (column1,column2,column3….) VALUES
(value1,value2,value3….)
To add a record in the database created earlier, type the following and click
Execute.
Example: Insert into SDetails
(“ID”,“Name”,“Rollno”,“DOB”,“Class”,“Phone”,“Email”,“Color”,“Location”) values
(‘8’,‘RanjithSingh’,’67’,‘12-03-99’,’X’,‘435363’,‘[email protected]’,‘White’, ‘Bihar’);
After inserting the data in to the table, use select query to view the updated table.
DELETE statement
Delete Statement is used to remove one or more records in a database.
Syntax: DELETE FROM ‘’table_name’’ WHERE ‘’condition’’;
Example: Delete from SDetails where ‘ID’=‘8’;

12|Contents
Execute select query to view the updated table

SORTING DATA
Sorting means to arrange the data in either ascending order or descending order.
Select the column(s) then click on sort buttons. The data will be displayed
accordingly.
To display sorted data using sql command write as follows:
Select * from “tablename” order by “fieldname”;
Select * from “tablename” order by “fieldname” desc;

Referential Integrity
Referential integrity is used to maintain accuracy and consistency of data in a
relationship.
In Base, data can be linked between two or more tables with the help of primary
key and foreign key constraints.
Referential integrity helps to avoid:
• Adding records to a related table if there is no associated record available in the
primary key table.
• Changing values in a primary if any dependent records are present in associated
table(s).
• Deleting records from a primary key table if there are any matching related
records available in associated table(s).
Creating and Editing Relationships between Tables
A relationship refers to an association or connection between two or more tables.
Relationships between tables helps to:
• Save time as there is no need to enter the same data in separate tables.
• Reduce data-entry errors.

13|Contents
• Summarize data from related tables.
You can create a relationship between any two tables by selecting
Relationships…option from the Tools menu.

Add the tables in amongst which you want to create the relationship. Select the
tables and click on Add button.

There are three types of relationships which can be created in tables:


1.ONE to ONE
2.ONE to MANY OR MANY to ONE
3.MANY to MANY
There are two ways to create the relationships between the tables:
a.Click on Insert option and select New Relation…option in Relation
Design window.
b. Drag the primary key column from one table and drop it on the key
column of another table.

One to One Relationship


In this relationship, both the tables must have primary key

14|Contents
One to Many Relationship
In this relationship, one of the table must have primary key column.
It signifies that one column of primary key table is associated with all the
columns of associated table.

Many to Many Relationship

In this relationship, not able has the primary key column.


It signifies that all the columns of primary key table are associated with all
the columns of associated table.

Remove the Relationships

15|Contents
The relationships applied on the tables can be removed also with the help of Delete
option. Right Click on the relationship thread and select Delete option.

SESSION4:RETRIEVE DATA USING QUERY


Query- Query is to collect specific information from the pool of data. A query helps
us join information from different tables and filter that information. Filtering means
that the query uses criteria you provide to hide some data and present only what
you want to see.
Some RDBMS provide a graphical means to create queries, but most RDBMS do not
do so. That’s where you use SQL(pronounced as “sequel”) or Structured Query
Language.
To retrieve data from database, we used Select statement.
SELECT Statement- A SELECT statement retrieves zero or more rows from one or
more database tables or database views. In most applications, SELECT is the most
commonly used Data Manipulation Language(DML)command.

The SELECT statement has many optional clauses:


•WHERE: specifies which rows to retrieve.
•ORDERBY: specifies an order in which the result should be arranged.
SYNTAX:(a) To retrieve a fixed number of columns:
SELECT(column1,column2,column3,…) FROM ‘’table_name’’
[WHERE condition]
[ORDER BY column];

16|Contents
Example- Select Name,Rollno from SDetails Where Class= ’10’ Order by ‘’Rollno’’ ;
(b)To retrieve all the columns in a table:
Syntax: SELECT * FROM table_name
Example- Select * from SDetails;
In order to execute queries click on the Queries option available on the left side
under database section, click Create Query in SQL View as shown below.

Awindowappearssimilartotheonedisplayedbelow.
You can type the query in the above window and execute it by using the F5 function
key or by clicking the icon in the window.
Grouping of Data
To display the records containing the same type of values “WHERE” clause can be
used with the Select SQL Command.
To get details about the list of students whose favorite color is blue, you can use:
select * from SDetails where Color=’Blue’;
After executing the select query the output will be shown similar to the one
displayed below.

17|Contents
To view records in ascending order of RollNo, from the table the select statement
will be: select * from SDetails order by Rollno ASC;

You can add, modify or delete records using the Insert, Update and Delete
commands.
To type and execute SQL commands, click on Tools>SQL. A window similar to the
one below will be displayed.

You can type the SQL Commands in the Command to execute space and click on
Execute.

UPDATE statement
Update statement is used for modifying records in a database.
SYNTAX: UPDATE ‘’table_name’’
SET column_name=value[,column_name=value...]
[WHERE‘’condition’’];
Example- Update SDetails set Location=‘Bhubaneswar’ where Rollno=14;

Type the following and click Execute. After execution you should see a updated
table.

SESSION 5: CREATE FORMS AND REPORTS USING WIZARD


18|Contents
FORM: A form provides the user a systematic way of storing information in to the
database. It is an interface in a user specified layout that lets users to view, enter,
and change data directly in database objects such as tables.
To create a form, Click on Forms option located under Database section (Figure
below).

Click Use Wizard to Create Form…option under Tasks group. The Form Wizard
dialog box appears as shown below.

You can select selective fields to be sent on to the form by selecting the field name
and clicking>button
To use all the fields in the table in a form, click the >> button.
Notice the fields displayed under Fields in the forms section(Figure below).

19|Contents
Click Next>. You see the Setup a subform step dialog box of the wizard as shown
below.

You can select the option AddSubform if you need to insert the contents in the
table in a separate form. Click Next>.
Select a style. Once you have selected a style, click Next>
A dialog box appears where in you can select the data entry model Click Next>. You
should see a dialog box where in you can specify the styles to be used in the form.
Click Next>. You see a dialog box where you can specify the name of the form. Click
Finish.
A form window appears. Notice that there cords in the table are displayed
automatically within the form that you just created.

20|Contents
You can add new records to the table using the form by clicking the symbol
located at the bottom as shown below.

21|Contents
You have learnt to create records using design view in the earlier sessions. You can
add records using the form as displayed below. Type the following data in the text
box provided in the box as shown below:

To view the saved records, Double-click SDetails(Tablename) under Tables section.


A window similar to the one below will be displayed; notice the record that you
created using a form is also displayed along with other records(Figure below).

Now enter three more records using the form and view them using the above
mentioned procedure.

REPORTS: A report helps to display the data in a summarized manner. It is used to


generate the overall workout come in a clear format. You can create reports in the
database.
Click on Reports section under Database in the OpenOfficebase application.
Once you select the option, you should see a window similar to the one displayed
below.

22|Contents
Now we can generate the report for the table created earlier.
Click on Use Wizard to Create Report…option available under Tasks.
Once you select the Use Wizard to Create Report…option. You should see a
window similar to one displayed below.

You have to select all the table fields by selecting the>>button, once you click the
button>>you should see a dialog box similar to the one displayed below.

Click Next>.

Once you click Next>. You should see a dialog box similar to the one displayed
below.

23|Contents
You can redefine the label of the fields in the reports or else you can set the
default name.
Click Next>.
Once you click Next>,you should see a dialog box similar to the one displayed
below.

You can define grouping for the fields of the table.


Click Next>.
Once you click Next>, you should see a dialog box. You can sort the field variables
in the report by selecting the appropriate field and sorting method.
Click Next>.
Once you click Next>,you should see a dialog box. You can select the layout of the
report by selecting the appropriate option available under the Layout of data down
list and you can also select the orientation of the report.
Click Next>.
Once you click Next>,you should see a dialog box.

24|Contents
You can define a name for the report or you can use the name of the table itself for
the report also.
Click Finish.
Once you click Finish you should see a window similar to the one displayed below
with the report.

Now create a report containing only Name, RollNo and Phonedetails. Use different
layouts for the report design.

25|Contents

You might also like